import java.util.Scanner;
public class Demo02 {
public static void main(String[] args) {
System.out.println("请输入一个字符串:");
String cc = new Scanner(System.in).nextLine();
char[] arr = cc.toCharArray();
int count1 =0;
int count2 =0;
int count3 =0;
int count4 =0;
for (int i = 0; i < arr.length; i++) {
if (arr[i]>=48&&arr[i]<=57){
count1++;
} else if (arr[i]>=97&&arr[i]<=123) {
count2++;
} else if (arr[i]>=65&&arr[i]<97) {
count3++;
} else {
count4++;
}
}
System.out.println("字符串中的数字有"+count1+"个");
System.out.println("字符串中的小写字母有"+count2+"个");
System.out.println("字符串中的大写字母有"+count3+"个");
System.out.println("字符串中的其他字符有"+count4+"个");
}
}
标签:arr,java,int,System,cc,查找,&&,字符串
From: https://blog.51cto.com/u_14978586/6975837