public static void main(String[] args) {
System.out.println("请输入一个字符串");
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
getNum(line);
}
public static void getNum(String line) {
int big = 0;
int small = 0;
int num = 0;
int other = 0;
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
if(c >= 'A' && c <= 'Z' ) {
big++;
}else if(c >= 'a' && c <= 'z') {
small++;
}else if(c >= '0' && c <= '9') {
num++;
}else {
other++;
}
}
System.out.println("大写:" + big + "个");
System.out.println("小写:" + small + "个");
System.out.println("数字:" + num + "个");
System.out.println("其它:" + other + "个");
}
} 作者: Hyperion 时间: 2016-6-3 23:00
记录一下