import java.util.Scanner;
public class Dome1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s;
boolean flag = true;
while (flag) {
System.out.println("请输入一个字符串:");
s = sc.nextLine();
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch >= 'a' && ch <= 'z' || ch > 'A' && ch < 'Z') {
flag = false;
break;
}else {
flag = true;
}
System.out.println("输入错误,请重新输入带字母的字符串");
}
int count = 0;
for (int i = 0; i <s.length() ; i++) {
char num = s.charAt(i);
if (num>'A'&&num<'Z') {
count++;
}
}
System.out.println("字符串中大写字母的个数为:"+count);
}
}
} |
|