您的位置:首页 > 编程语言 > Java开发

Introduction to Java Programming编程题9.15<求字符串中大写字母的个数>

2015-08-27 22:51 507 查看
/*
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  字符统计