/*
java CountUpperCase RollingInTheDeep
The uppercase total is: 4
java CountUpperCase Rolling In The Deep Adele Steven Sharp Nelson Jon Schmidt.
The uppercase total is: 10
*/
public class CountUpperCase {
public static void main(String[] args) {
int totalUpperCase = 0, i = 0;
while (i < args.length) {
totalUpperCase += countUpperCase(args[i]);
i++;
}
System.out.println("The uppercase total is: " + totalUpperCase);
}
public static int countUpperCase(String s) {
int totalUpperCase = 0;
for (int i = 0; i < s.length(); i++) {
if (Character.isUpperCase(s.charAt(i)))
totalUpperCase++;
}
return totalUpperCase;
}
}
Introduction to Java Programming编程题9.15<求字符串中大写字母的个数>
Java大写字符计数器
最新推荐文章于 2025-11-08 16:34:43 发布
本文介绍了一个简单的Java程序,该程序能够接收命令行参数并统计其中的大写字母总数。通过遍历字符串中的每个字符并检查其是否为大写来实现这一功能。
284

被折叠的 条评论
为什么被折叠?



