Java字符判断的小例子

时间:2022-03-26 05:33:43

代码入下:

 

复制代码代码如下:

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("此字符不是字母"); 
                } 
                else if(Character.isLetter(ch)) 
                { 
                    if (!Character.isLowerCase(ch)) 
                    { 
                        System.out.println("此字符是大写字母"); 
                    } 
                    else if (Character.isLowerCase(ch)) 
                    { 
                        System.out.println("此字符是小写字母"); 
                    } 
                } 
            } 
        } 
        catch(Exception e) 
        { 

        } 
    } 

}

 

 


效果如图所示:

 

Java字符判断的小例子