( 对大写字母计數)编写一个程序,提示用户输人一个字符串,然后显示该字符串中大写字母的 数目。
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); int count = 0; for (int i = 1; i <= s.length(); i++) { String str = String.valueOf(s.charAt(i - 1)); if (str.equals(str.toUpperCase())) { count++; } } System.out.println(count); scanner.close(); }