/*
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<求字符串中大写字母的个数>
最新推荐文章于 2021-09-15 13:34:53 发布