码迷,mamicode.com
首页 > 其他好文 > 详细

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

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

标签:style   java   for   line   new   amp   

这道题我错了一次,主要是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:统计大写字母个数

标签:style   java   for   line   new   amp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!