import java.util.*;
public class Test7 {
public static void main(String[] args) {
int word = 0;
int number = 0;
int space = 0;
int others = 0;
Scanner input = new Scanner(System.in);
System.out.println("Enter some characters:");
String s = input.nextLine();
char[] n = s.toCharArray();
for(int i=0;i<n.length;i++){
if(Character.isLetter(n[i])){
//判断是否字母
word++;
}
else if(Character.isDigit(n[i])){
//判断是否数字
number++;
}
else if(Character.isSpaceChar(n[i])){
//判断是否空格键
space++;
}
else{
//以上都不是则认为是其他字符
others++;
}
}
System.out.println("字母个数:"+word);
System.out.println("数字个数:"+number);
System.out.println("空格个数:"+space);
System.out.println("其他字符个数:"+others);
}
}
public class Test7 {
public static void main(String[] args) {
int word = 0;
int number = 0;
int space = 0;
int others = 0;
Scanner input = new Scanner(System.in);
System.out.println("Enter some characters:");
String s = input.nextLine();
char[] n = s.toCharArray();
for(int i=0;i<n.length;i++){
if(Character.isLetter(n[i])){
//判断是否字母
word++;
}
else if(Character.isDigit(n[i])){
//判断是否数字
number++;
}
else if(Character.isSpaceChar(n[i])){
//判断是否空格键
space++;
}
else{
//以上都不是则认为是其他字符
others++;
}
}
System.out.println("字母个数:"+word);
System.out.println("数字个数:"+number);
System.out.println("空格个数:"+space);
System.out.println("其他字符个数:"+others);
}
}