A statistical exercise class String string number of uppercase and lowercase letters and numeric characters

public  class StringPractice {
     public  static  void main (String [] args) {
         // Create a text scanner 
        Scanner SC = new new Scanner (the System. in ); 
        the System. OUT .println ( " Enter a string: " ); 
        String STR = sc.next (); 

        // define three variable used to count the uppercase letters, lowercase letters, numbers, number 
        int bigCount = 0 ;
         int smallCount = 0 ;
         int numCount = 0 ; 

        // traversal string, each character judgment 
        for (int i = 0;i<str.length();i++){
            char chs = str.charAt(i);
            //如果
            if (chs >= 'A' && chs <= 'Z'){
                bigCount++;
            }else if (chs >= 'a' && chs <= 'z'){
                smallCount++;
            }else if (chs >= '0'CHS && <= ' . 9 ' ) { 
                numCount ++ ; 
            } the else { 
                the System. OUT .println ( " the character " + CHS + " illicit " ); 
            } 
        } 
        // output of 
        the System. OUT .println ( " uppercase characters: " bigCount + + " a " ); 
        System. OUT .println ( " lowercase characters: " + + smallCount "More "); 
        The System. OUT .println ( " numeric characters: " + numCount + " a " ); 


    } 
}

 

Guess you like

Origin www.cnblogs.com/libinhong/p/10990072.html