判断一个字符是不是一个字母 java
// 判断一个字符是否是中文
public static boolean isChinese(char c) {
return c = 0x4E00 c = 0x9FA5;// 根据字节码判断
}
// 判断一个字符串是否含有中文
public static boolean isChinese(String str) {
if (str == null) return false;
for (char c : str.toCharArray()) {
if (isChinese(c)) return true;// 有一个中文字符就返回
}
return false;
}
java 如何判断一个字符是不是字母
用正则表达式匹配。比如输入为Strings,s.matches(“[0-9a-zA-Z]*”)返回true,就可以了~
java如何判断输入的是数字还是字母
还有可能输入其他特殊符号 如果你只需输入数字,捕获异常时最方便的了。
附代码:
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 (a0)
System.out.print(a+”是一个正数。”);
else
{if (a==0)
System.out.print(“您输入的数字是零。”);
else
System.out.print(a+”是一个负数。”);
}
}
}
java 判断 是否 字母
import java.util.Scanner;
/**
* 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) + “不是字母”);
}
}
}
}
}
效果:
希望能帮到你,望采纳。
Java语言怎么判断是不是字母
字母包括大写和小写 需要分别判断
组合起来就是
(ch=’A’ ch =’Z’) || (ch=’a’ ch =’z’)
前面的是大写 后面是小写。