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

来源:互联网 发布:linux vm commit over 编辑:程序博客网 时间:2024/06/02 16:28
/*java CountUpperCase RollingInTheDeepThe uppercase total is: 4java 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;    }}
0 0
原创粉丝点击