zoukankan      html  css  js  c++  java
  • 找出字符串有有多少个大写字母、小写字母及其它

    public class TestStringCharAt {
        /**
         * 找出字符串有有多少个大写字母、小写字母及其它
         */
        public static void main(String[] args) {
            String str = "AADDBDDCDEFddlfafdfaifABDILIWcdafd122~!!@AbC";
            char ch = 0;
            int upperNum = 0;
            int lowerNum = 0;
            int otherNum = 0;
            /**
             * 方法一
             *         for (int i=0;i<str.length();i++) {
             *             ch = str.charAt(i);
             *             if (ch >= 'A' && ch <= 'Z') {
             *                 upperNum ++;
             *             }
             *             else if (ch >='a' && ch <= 'z' ) {
             *                 lowerNum ++;
             *             }else {
             *                 otherNum ++;
             *             }
             *         }
             *
             */
    
            //方法二
            String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            String lower = "abcdefghijklmnopqrstuvwxyz";
            for (int i=0;i<str.length();i++) {
                ch = str.charAt(i);
                if (upper.indexOf(ch) != -1) {
                    upperNum ++;
                }else if (lower.indexOf(ch) != -1) {
                    lowerNum ++;
                }else {
                    otherNum ++;
                }
            }
    
            System.out.println(upper.indexOf('A'));
    
            System.out.println("共有" + upperNum + "个大写字母");
            System.out.println("共有" + lowerNum + "个小写字母");
            System.out.println("共有" + otherNum + "其它字母");
        }
    
    }
  • 相关阅读:
    java代理的深入浅出(一)-Proxy
    事件分发模型的设计与实现
    LibProject使用theme无效。
    HeaderGridView
    android开源代码
    IOS学习4
    IOS学习3
    IOS学习2
    Mac上添加adb_usb.ini
    OC学习-1
  • 原文地址:https://www.cnblogs.com/janson071/p/9604465.html
Copyright © 2011-2022 走看看