package mumu;
import java.util.Scanner;
/*
* 1、输入一个字符串,分别统计出其中英文字母、空格、数字和其它字符的数量
*/
public class 木木01 {
public static void main(String[] args) {
char[] chs = new Scanner(System.in).nextLine().toCharArray();
int a = 0,b = 0 ,c = 0,d = 0;
for (int i = 0; i < chs.length; i++) {
if ( chs[i] >= 'A' && chs[i] <= 'Z' ) {
a++;
} else if(chs[i] >= 'a' && chs[i] <= 'z'){
a++;
}else if(chs[i] >= '0' && chs[i] <= '9'){
b++;
}else if(' ' == chs[i] ){
c++;
}else{
d++;
}
}
System.out.println("字母有"+a+" "+"数字有"+b+" "+"空格有"+c+" "+"其他字符有"+d+" ");
}
}
/*public static void main(String[] args) {
LinkedHashMap<Character, Integer> map = new LinkedHashMap<Character, Integer>();
for (Character key : new Scanner(System.in).next().toCharArray()) {
map.put(key,!map.containsKey(key)?1:map.get(key)+1);
}
for (Character key : map.keySet()) {
System.out.print(key+"("+map.get(key)+")");
}
}*/
|
|