A small example of Java character determination

  • 2020-04-01 02:15:00
  • OfStack

Code:


import java.io.*; 
public class Practice { 
    public static void main(String[] args) { 
        // TODO Auto-generated method stub 
        BufferedReader buf; 
        buf=new BufferedReader(new InputStreamReader(System.in));        
        try
        { 
            String str=buf.readLine(); 
            for(int i=0;i<str.length();i++){  
                char ch = str.charAt(i); 
                //System.out.println(ch); 
                if(!Character.isLetter(ch)) 
                { 
                    System.out.println(" This character is not a letter "); 
                } 
                else if(Character.isLetter(ch)) 
                { 
                    if (!Character.isLowerCase(ch)) 
                    { 
                        System.out.println(" This character is uppercase "); 
                    } 
                    else if (Character.isLowerCase(ch)) 
                    { 
                        System.out.println(" This character is lowercase "); 
                    } 
                } 
            } 
        } 
        catch(Exception e) 
        { 

        } 
    } 

} 

The effect is shown in the figure:

< img border = 0 SRC = "/ / files.jb51.net/file_images/article/201309/2013911145711280.jpg" >


Related articles: