题目:
键盘输入一个字符串,并且统计其中各种字符出现的次数。
种类有:大写字母,小写字母,数字,其他[/size]
public class Demo02StringCount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String input = sc.next();
int countUpper = 0;
int countLow = 0;
int countNumber = 0;
int countother = 0;
char[] charArray = input.toCharArray();
for (int i = 0; i < charArray.length; i++) {
char ch = charArray[i];
if ('A'<=ch&&ch<='Z'){
countUpper++;
}else if ('a'<=ch&&ch<='z'){
countLow++;
}else if ('0'<=ch&&'9'<=ch){
countNumber++;
}else {
countother++;
}
}
System.out.println("大写字母有:"+countUpper);
System.out.println("小学字母有:"+countLow);
System.out.println("数字有"+countNumber);
System.out.println("其他字符有:"+countother);
}
}
请问问题出在哪里呢?