public static void main(String[] args){
int abcCount = 0;
int numCount = 0;
int SpaceCount = 0;
int otherCount = 0;
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[] ch = str.toCharArray();
for(int i = 0; i < ch.length;i++){
if(Character.isLetter(ch[i])){abcCount++;}
else if(Character.isDigit(ch[i])){numCount++;}
else if(Character.isSpaceChar(ch[i])){SpaceCount++;}
else{otherCount++;}
}System.out.println("字母数是:"+ abcCount);
System.out.println("数字数是:"+ numCount);
System.out.println("空格数是:" + SpaceCount);
System.out.println("其他的是:" + otherCount);
}
}
时间: 2024-10-10 14:51:31