首页 > 其他 > 详细

华为OJ:统计大写字母个数

时间:2014-07-09 12:17:36      阅读:362      评论:0      收藏:0      [点我收藏+]

这道题我错了一次,主要是A跟Z边界没有考虑,其他的就是记得测试时用nextLine,因为字符串可能可能有空格。

import java.util.Scanner;
public class bigLetterCount {
	public static int CalcCapital(String str){
		int count=0;
		for(int i=0;i<str.length();i++){
			if('A'<=str.charAt(i)&&str.charAt(i)<='Z')count++;
		}
		return count;
	}
	
	
	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String s=input.nextLine();
		System.out.println(CalcCapital(s));
		
	}
}

华为OJ:统计大写字母个数,布布扣,bubuko.com

华为OJ:统计大写字母个数

原文:http://blog.csdn.net/whu_sky/article/details/37584013

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!