代码如下:
public static void main(String[] args_) throws Exception {String str1 = "zhang张123";String str2 = "zhang123";System.out.println(checkStringType(str1)); // 包含中文字符System.out.println(checkStringType(str2)); // 不包含中文字符}public static String checkStringType(String inputStr) {// 使用正则表达式匹配中文字符Pattern chinesePattern = Pattern.compile("[\u4e00-\u9fa5]");// 检查字符串中是否包含中文字符boolean hasChinese = chinesePattern.matcher(inputStr).find();if (hasChinese) {return "包含中文字符";}else{return "不包含中文字符";}}