描述 输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。

输入描述: 输入一行字符串,可以有空格

输出描述: 统计其中英文字符,空格字符,数字字符,其他字符的个数

示例1

输入: 1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\/;p0-=\][

输出: 26 3 10 12

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.nextLine();
        int english = 0 ,space = 0,num = 0,other = 0;
        for(int i = 0;i<s.length();i++){
            char c = s.charAt(i);
            if(c >= 'a' && c <= 'z'){
                english++;
            }else if(c >= 'A' && c <= 'Z'){
                english++;
            }
            else if(c >= '0' && c <= '9'){
                num++;
            }else if(c == 32){
                space++;
            }else{
                other++;
            }
        }
        
        System.out.println(english);
        System.out.println(space);
        System.out.println(num);
        System.out.println(other);
    }
}

对应其ASCII码值