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