A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© Over_Mstuang 中级黑马   /  2015-8-12 18:27  /  306 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package cn.itcast.chapterll;
//import Java.util.Scanner;
/*
* 统计大写小写字符的个数
*
* 举例:
*                 Hello12345World
*
*                 大写:2
*                 小写:8
*                 数字:5
*
* 思路:
*                 A:定义三个统计变量
*                 B:获取到每一个字符。遍历字符串。
*                 C:判断是属于哪种范围的
*                         大写:65-90
*                         小写:97-122
*                         数字:48-57
*                C:是哪种哪种++
*/
public class HelloWroldTest {
        public static void main(String[] args) {
                String s = "Hello12345Wrold";
                               
                                //                 A:定义三个统计变量
                                int bigCount = 0;
                        int smallCount = 0 ;
                                int numberCount = 0;
                               
                                for (int x = 0; x < s.length(); x++) {
                                        char ch = s.charAt(x);

                                if (ch >= 'A'&&ch<='Z') {bigCount ++;
                                       
                                }else if (ch>='a'&&ch <= 'z') {smallCount++;
                               
                                       
                                }else if (ch>='0'&&ch<='9') {numberCount++;
                               
                                       
                                }
                                else break;
               
                                }
                                System.out.println("大写:"+bigCount);
                                System.out.println("小写:"+smallCount);
                                System.out.println("数字:"+numberCount);
        }

}

1 个回复

倒序浏览
多谢分享~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马