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

华为OJ平台——统计字符串中的大写字母

时间:2016-07-02 15:53:38      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

题目描述:

  统计字符串中的大写字母的个数

输入:

  一行字符串

输出:

  字符串中大写字母的个数(当空串时输出0)

 

思路:

  这一题很简单,直接判断字符串中的每一个字符即可,唯一要注意的一点是输入的字符串可能包含空格,所以读入的时候要用nextLine()方法

 

 1 import java.util.Scanner;
 2 
 3 public class CountCaptial {
 4 
 5     public static void main(String[] args) {
 6         Scanner cin = new Scanner(System.in) ;
 7         String str = cin.nextLine() ;
 8         cin.close() ;
 9         
10         int count = 0 ;
11         char temp ;
12         for(int i = 0 ; i < str.length() ; i++){
13             temp = str.charAt(i) ;
14             if((temp <= ‘Z‘) && ( temp >= ‘A‘)){
15                 count++ ;
16             }
17         }
18         
19         System.out.println(count);
20 
21     }
22 
23 }

 

华为OJ平台——统计字符串中的大写字母

标签:

原文地址:http://www.cnblogs.com/mukekeheart/p/5635461.html

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