/**
* java 判断 是否 字母
*
* @author Retror
*
*/
public class IsStr {
public static void main(String[] args) {
while (true) {
Scanner scan = new Scanner(System.in)
String str = scan.nextLine()
for (int i = 0 i < str.length() i++) {
if ((str.charAt(i) <= 'Z' && str.charAt(i) >= 'A')
|| (str.charAt(i) <= 'z' && str.charAt(i) >= 'a')) {
System.out.println(str.charAt(i) + "是字母")
} else {
System.out.println(str.charAt(i) + "不是字母")
}
}
}
}
}
效果:
希望能帮到你,望采纳。
字母包括大写和小写 需要分别判断
组合起来就是
(ch>='A' && ch <='Z') || (ch>='a' && ch <='z')前面的是大写 后面是小写。
还有可能输入其他特殊符号 如果你只需输入数字,捕获异常时最方便的了。附代码:
import java.util.Scanner
public class nomb {
public static void main(String[] args) {
System.out.print("please input the number:")
int a
Scanner in=new Scanner(System.in)
try{
a=in.nextInt()
}catch(Exception e){
System.out.println("input error")
return
}
if (a>0)
System.out.print(a+"是一个正数。")
else
{if (a==0)
System.out.print("您输入的数字是零。")
else
System.out.print(a+"是一个负数。")
}
}
}