Enter a line of characters to calculate the number of English letters, spaces, numbers, and other characters, and the number of lines
Public class Test2 {
Public static void main (String [] args ){
// TODO Auto-generated method stub
Int abcCount = 0; // number of English letters
Int spaceCount = 0; // Number of Space key
Int numCount = 0; // number of digits
Int otherCount = 0; // number of other characters
String str = "hhhhh666 yh4st66 ****";
Char [] ch = str. toCharArray ();
For (int I = 0; I <ch. length; I ++ ){
If (Character. isLetter (ch [I]) {
// Determine whether it is a letter
AbcCount ++;
} Else if (Character. isDigit (ch [I]) {
// Determine whether the number is correct.
NumCount ++;
} Else if (Character. isSpaceChar (ch [I]) {
// Determine whether the Space key is used
SpaceCount ++;
} Else {
// Other characters are considered if none of the above are true.
OtherCount ++;
}
}
System. out. println ("letter count:" + abcCount );
System. out. println ("number:" + numCount );
System. out. println ("number of spaces:" + spaceCount );
System. out. println ("other characters:" + otherCount );
}
}