輸入一行字符,分別統計出其中英文字母、數字、空格和其他字符的個數。
輸入
一行字符
輸出
統計值
樣例輸入
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
樣例輸出
23 16 2 4
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String n = in.nextLine();
int count1=0;
int count2=0;
int count3=0;
int count4=0;
char a[] = n.toCharArray();
for(int i=0;i<a.length;i++){
if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z'){
count1++;
}
else if(a[i]==' '){
count2++;
}
else if(a[i]>='0'&&a[i]<='9'){
count3++;
}
else
count4++;
}
System.out.print(count1+" "+ count3 + " "+count2+" "+count4);
}
}