首页 > 编程 > Java > 正文

Java字符判断的小例子

2019-11-26 15:58:09
字体:
来源:转载
供稿:网友

代码入下:

复制代码 代码如下:

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)
        {

        }
    }

}


效果如图所示:

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表