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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© funny 中级黑马   /  2015-9-6 23:01  /  408 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.wf.bean;

import javax.swing.text.StyleContext.SmallAttributeSet;

public class B {

        /**
         * 需求:统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数,其他字符出现的次数。
         */
        public static void main(String[] args) {
                        String s = "ABCDEabcd123456!@#$%^";
                        int big = 0;
                        int small = 0;
                        int count = 0;
                        int other = 0;
                       
                        for (int i = 0; i < s.length(); i++) {
                                char c1 = s.charAt(i);
                                if(c1>='A' && c1<= 'Z'){
                                        big++;
                                }else if (c1>='a' && c1<='z') {
                                        small++;
                                }else if (c1>='0' && c1<='9') {
                                        count++;
                                }else {
                                        other++;
                                }
                        }
                        System.out.println(big);
                        System.out.println(small);
                        System.out.println(count);
                        System.out.println(other);
        }

}

1 个回复

倒序浏览
最上面的导包有点多余了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马