//获取输入字符串的 数字 大写字母 小写字母分别的个数
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String line = sc.nextLine();
int number = 0;
int dazimu = 0;
int xzm = 0;
for (int i = 0; i <line.length() ; i++) {
char c = line.charAt(i);
if(c>='A'&&c<='Z'){
dazimu++;
}else if(c>='0'&&c<='9'){
number++;
}else if(c>='a'&&c<='z'){
xzm++;
}
}
System.out.println("小字母:"+xzm+"个");
System.out.println("大字母:"+dazimu+"个");
System.out.println("数字:"+number+"个");
}
} |
|