Count the number of English letters, spaces, numbers and other characters

Question: Enter a line of characters and count the number of English letters, spaces, numbers and other characters in it.
1. Program analysis: Using the while statement, the condition is that the input character is not '/n '. */


public class SeventhCharacterStatistics {
static int digital = 0;
static int character = 0;
static int other = 0;
static int blank = 0 ;
public static void main(String[] args) {
   char[] ch = null;
   Scanner sc = new Scanner(System.in);
   String s = sc.nextLine();
   ch = s.toCharArray();
 
 
   for(int i=0; i<ch.length; i++) {
    if(ch[i] >= '0' && ch[i] <= '9') {
     digital ++;
    } else if((ch[i] > = 'a' && ch[i] <= 'z') || ch[i] > 'A' && ch[i] <= 'Z'


     blank ++;
    } else {
     other ++;
    }
  
   }

   System.out.println("Number of numbers: " + digital);
   System.out.println("Number of English letters: " + character);
   System.out. println("Number of blanks: " + blank);
   System.out.println("Number of other characters: " + other );
}

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326682973&siteId=291194637
Recommended