Home > Back-end >  Keyboard input a string, and the statistics of the number of occurrences of various characters. Type
Keyboard input a string, and the statistics of the number of occurrences of various characters. Type

Time:02-24

Title:
Keyboard input a string, and the statistics of the number of occurrences of all kinds of characters,
Types are: uppercase letters, lowercase letters, Numbers and other [/size]
Public class Demo02StringCount {
Public static void main (String [] args) {
Scanner sc=new Scanner (System. In);
System. The out. Println (" please input a string: ");
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 & lt; CharArray. Length; I++) {
Char ch=charArray [I];
If (' A '& lt;=ch& & Ch<='Z') {
CountUpper++;
} else if (' a '& lt;=ch& & Ch<='z') {
CountLow++;
} else if (' 0 '& lt;=ch& & '9' & lt;=ch) {
CountNumber++;
} else {
Countother++;
}
}
System. The out. Println (" capital letters: "+ countUpper);
System. The out. Println (" primary school letters: "+ countLow);
System. The out. Println (" number "+ countNumber);
System. The out. Println (" other characters are: "+ countother);
}
}




Can you tell me where the problem is?

CodePudding user response:

Else if (' 0 '& lt;=ch& & '9' & lt;=ch)