例:
输入abcdABCDe*&12
输出 小写5,大写4,其他4
import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int capital=0,lowercase=0,other=0;
System.out.println("请输入一行字符串");
String str = sc.nextLine();
//第一种写法
/*char[] ch = str.toCharArray();//字符串转换为数组
for (int i = 0; i < ch.length; i++) {
if (ch[i]>='a' && ch[i] <='z') {
lowercase++;
} else if (ch[i]>='A' && ch[i] <='Z') {
capital++;
} else {
other++;
}
}*/
//第二种写法
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >='a' && c <='z') {
lowercase++;
} else if (c >='A' && c <='Z') {
capital++;
} else {
other++;
}
}
System.out.println("大写字母的个数:"+capital);
System.out.println("小写字母的个数:"+lowercase);
System.out.println("其它字符串的个数:"+other);
}
}