[7] string processing program 7

Title: Enter the line of characters, respectively, the statistics of the number of letters, spaces, numbers and other characters in them.
Cheng Analysis: Using the while statement, the condition is not a character input '\ n'.
package Wang job; 

Import java.util.Scanner; 

public  class program processing strings 7 { 

    public  static  void main (String [] args) {
         // the TODO Auto-Generated Method Stub 
Scanner in = new new Scanner (the System.in); 
String STR; 
int NUM = 0 ;
 int Letter = 0 ;
 int space = 0 ;
 int OTHER = 0 ; 
STR = in.nextLine (); // returns the n rows including spaces 
for ( int I = 0; I <str.length () ; I ++ ) { 

IF(str.charAt(i)>='a'&&str.charAt(i)<='z'||str.charAt(i)>='A'&&str.charAt(i)<='Z') {
    letter++;
}
else if(str.charAt(i)>='0'&&str.charAt(i)<='9') {
     num++;
 }
else if(str.charAt(i)==' ') {
     space++;
 }
else {
    other++;
}
}
System.out.println("字母的个数:"+letter);
System.out.println("数字的个数:"+num);
System.out.the println ( Space);"number of spaces:" +
System.out.println ("Other number:" + OTHER); 
    } 

}

 

Guess you like

Origin www.cnblogs.com/Oren-wu/p/12285895.html