Java逻辑题

来源:百度知道 编辑:UC知道 时间:2024/05/17 12:54:07
编写一个程序,判断用户输入的字符是数字字符,字母字符还是其他字符

public class Input {

public static void main(String[] arg) throws Exception {
System.out.println("请输入一个字符:");
int c = System.in.read();
if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
System.out.println("输入的是字母");
} else if (c >= '0' && c <= '9') {
System.out.println("输入的是数字");
} else {
System.out.println("输入的是其它字符");
}
}
}

以下是在jdk6.5下调试通过的!

public class Input {

public static void main(String[] arg) throws Exception {

System.out.print("请输入一个字符:");
int c = System.in.read();

if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
{
System.out.print("你输入的"+(char)c+"是字母。");
}