2024-05-24 07:39:37
1、编写代码,统计大写字母数量,
int cnt_upper = 0;
String regex_u = "[A-Z]";
Pattern p3 = Pattern.compile(regex_u);
java.util.regex.Matcher m3 = p3.matcher(str);
while (m3.find()) {
cnt_upper++;
}
System.out.print("大写字母数量:");
System.out.println(cnt_upper);
2、编写代码,统计小写字母数量,
int cnt_lower = 0;
String regex_l = "[a-z]";
p3 = Pattern.compile(regex_l);
m3 = p3.matcher(str);
while (m3.find()) {
cnt_lower++;
}
System.out.print("小写字母数量:");
System.out.println(cnt_lower);
3、编写代码,统计数字数量,
int cnt_num = 0;
String regex_n = "[0-9]";
p3 = Pattern.compile(regex_n);
m3 = p3.matcher(str);
while (m3.find()) {
cnt_num++;
}
System.out.print("数字数量:");
System.out.println(cnt_num);
4、输入测试字符串,String str = "A123Bde456EfG",执行程序,输出测试结果,
2024-05-24 18:39:01