Java程序检查输入的字符是否为ASCII 7位数字和字符
检查输入的值是否为ASCII 7位数字和字符(字母数字),检查字符的ASCII值是否存在 −
A to Z Or a to z Or 0 to 9
在此,我们有以下值 −
char one = '5';
现在,我们已经使用if-else对ASCII 7位数字和字符检查了一些条件。
if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
System.out.println("Given value is numeric and character (alphanumeric)!");
} else {
System.out.println("Given value is not numeric and character!");
}示例
public class Demo {
public static void main(String []args) {
char one = '5';
if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
System.out.println("Given value is numeric and character (alphanumeric)!");
} else {
System.out.println("Given value is not numeric and character!");
}
}
}输出
Given value is numeric and character (alphanumeric)!
让我们看另一个示例 −
示例
public class Demo {
public static void main(String []args) {
char one = 'V';
if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
System.out.println("Given value is numeric and character (alphanumeric)!");
} else {
System.out.println("Given value is not numeric and character!");
}
}
}输出
Given value is numeric and character (alphanumeric)!
广告
数据结构
联网
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP