//Character方法数量统计
public class test24 {public static void main(String[] args) {char ch = 'A';//使用构造方法Character obj1 = new Character('中');//使用静态方法Character obj2 = Character.valueOf(ch);char[] arr = {'5', 'A', 'a', 'C', 'D', 'U', '5', '9',' ','J','9'};countChar(arr);}public static void countChar(char[] chs) {int letter = 0;//字母数量int upper = 0;//大写字母int lower = 0;//小写字母int sum = 0;//数字数量int space = 0;//空格数量for(int i=0;i<chs.length;i++){if(Character.isLetter(chs[i])){letter++;if(Character.isUpperCase(chs[i])){upper++;}else{lower++;}}else if(Character.isDigit(chs[i])){sum++;}else if(Character.isWhitespace(chs[i])){space++;}}System.out.println("字母"+letter);//字母System.out.println("大写字母"+upper);//大写字母System.out.println("小写字母"+lower);//小写字母System.out.println("数字"+sum);//数字System.out.println("空格"+space);//空格}
}
运行结果