题解 | #统计大写字母个数#

统计大写字母个数

http://www.nowcoder.com/practice/434414efe5ea48e5b06ebf2b35434a9c

import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            String s = input.nextLine();
            System.out.println(count(s));
        }
    }
    public static int count(String s){
        int count=0;
        char[] cs=s.toCharArray();
        for(char c:cs){
            if(c>='A' && c<='Z'){
                count++;
            }
        }
        return count;
    }
}
全部评论

相关推荐

7 3 评论
分享
牛客网
牛客企业服务