public class Demo { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入一个字符串"); String s=sc.nextLine(); char[] arr=s.toCharArray(); int upperCount=0; int lowerCount=0; int digitCount=0; for (int i = 0; i < arr.length; i++) { if(Character.isUpperCase(arr[i])){ upperCount++; }else if(Character.isLowerCase(arr[i])){ lowerCount++; }else if(Character.isDigit(arr[i])){ digitCount++; } } System.out.println("大写字母"+upperCount+"个,小写字母"+lowerCount+"个,数字"+digitCount+"个"); } } |