zoukankan      html  css  js  c++  java
  • Java 练习:求指定字符串中大写字母,小写字母,其他字符分别的个数。

    /*
    public class Test1{
        public static void main(String[]args){
            String s = "abcdeEFHDKEI38475    ";
            char a[] = s.toCharArray();
            int lower = 0,upper = 0,other = 0;
            for(int i=0; i<a.length; i++){
                if(a[i]<='z' && a[i]>='a')    
                    lower++;
                else if(a[i]<='Z' && a[i]>='A') 
                    upper++;
                else 
                    other++;
            }
                 System.out.println(lower);
                 System.out.println(upper);
                 System.out.println(other);
        }
    }
    */
    
    /*
    public class Test1{
        public static void main(String[]args){
            String s = "abcdeEFHDKEI38475    ";
            int lower = 0,upper = 0,other = 0;
            for(int i=0; i<s.length; i++){
                char c = s.charAt(i);
                if(c<='z' && c>='a')    
                    lower++;
                else if(c <='Z' && c >='A') 
                    upper++;
                else 
                    other++;
            }
                 System.out.println(lower);
                 System.out.println(upper);
                 System.out.println(other);
        }
    }
    */
    /*
    public class Test1{
        public static void main(String[]args){
            String sL = "abcdefghijklmnopqrstuvwxyz";
            String sU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            String s = "abcdeEFHDKEI38475    ";
            int lower = 0,upper = 0,other = 0;
            for(int i=0; i< s.length(); i++){
                char c = s.charAt(i);
                if(sL.indexOf(c) != -1)    
                    lower++;
                else if(sU.indexOf(c) != -1) 
                    upper++;
                else 
                    other++;
            }
                 System.out.println(lower);
                 System.out.println(upper);
                 System.out.println(other);
        }
    }
    */
    
    public class Test1{
        public static void main(String[]args){
            String sL = "abcdefghijklmnopqrstuvwxyz";
            String sU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            String s = "abcdeEFHDKEI38475    ";
            int lower = 0,upper = 0,other = 0;
            for(int i=0; i< s.length(); i++){
                char c = s.charAt(i);
                if(Character.isLowerCase(c))    
                    lower++;
                else if(Character.isUpperCase(c)) 
                    upper++;
                else 
                    other++;
            }
                 System.out.println(lower);
                 System.out.println(upper);
                 System.out.println(other);
        }
    }
    

      关键思路:将字符串中每个字符提取出来,然后比较。具体查看Java API文档。https://docs.oracle.com/javase/8/docs/api/index.html

  • 相关阅读:
    使用边缘计算来改变5G世界中的网络
    解开关于人工智能的六个迷思
    哪些数据将成为区块链系统的关键数据?
    如何通过7个步骤构建机器学习模型
    人工智能的发展体现了人类社会由实向虚的趋势
    5G技术与人工智能的智能结合
    量子计算总是混合的,这需要不断协调
    7.5省队集训 tree
    bzoj2989&4170: 数列
    bzoj1010: [HNOI2008]玩具装箱toy
  • 原文地址:https://www.cnblogs.com/leafh/p/8684340.html
Copyright © 2011-2022 走看看