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

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

时间:2017-04-02 17:32:32      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:lin   out   stat   array   ring   java   sys   i++   can   

可将字符串转为字符数组,然后对数组进行遍历,进而统计大写字母的个数。

下面给出代码:

import java.util.Scanner;

public class Main {
  public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    String str = in.nextLine();
    int count = 0;
    char ch[] = str.toCharArray();  //转为字符数组
    for(int i = 0;i<ch.length;i++){
      if(ch[i]>=‘A‘&&ch[i]<=‘Z‘){
      count++;  //遍历数组,进行统计
    }
  }
    System.out.println(count);
  }
}

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

标签:lin   out   stat   array   ring   java   sys   i++   can   

原文地址:http://www.cnblogs.com/cppeterpan/p/6659354.html

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