jzxx1053统计大写英文字母的个数

题目描述
算算以‘.’结束的一串字符中含有多少个大写的英文字母。

输入
输入一串字符,以.结束

输出
输出一行,即这串字符中大写字母的个数。

样例输入
PRC,PRC,I’m from China.
样例输出
8

传送门

满分代码:
import java.util.Scanner;
public class Main  {
		public static int getNum(String s) {
			int r = 0;
			for(int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				if(c >= 'A' && c <= 'Z') {
					r++;
				}
			}
			return r;
		}  public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			String s = sc.nextLine();
			int x = getNum(s);
			System.out.println(x);
		}
}

猜你喜欢

转载自blog.csdn.net/lyz060510/article/details/88749131