2.从键盘上输入10个字符到数组中,
并将其转换为字符串,统计该字符串中大写字母、小写字母和其他字符的个数。
public static void main(String[] args) { Scanner scanner=new Scanner(System.in); char[] chars=new char[5]; for (int i = 0; i < chars.length; i++) { System.out.println("请输入一个字符:"); chars[i]= scanner.nextLine().charAt(0); } String s=String.valueOf(chars); System.out.println(s); int d=0,x=0,others=0; for (int i = 0; i < chars.length; i++) { if (chars[i]<='Z'&&chars[i]>='A'){ d++; }else if (chars[i]<='z'&&chars[i]>='a'){ x++; }else{ others++; } } System.out.println("大写字母有"+d+"个。"); System.out.println("小写字母有"+x+"个。"); System.out.println("其他有"+others+"个。"); }