Java程式 檢查輸入的值是否是ASCII 7位控制字元
要檢查輸入的值是否是ASCII 7位控制字元,請檢查字元的ASCII值在32和127之前。這些就是控制字元。
在這裡,我們有一個字元。
char one = ' n ';
現在,我們用if-else檢查一個條件,以檢查字元是否小於32(ASCII)並等於127。
if (one < 32 || one == 127) {
System.out.println("Given value is a control character!");
} else {
System.out.println("Given value is not a control character!");
}例子
public class Demo {
public static void main(String []args) {
char one = '
';
if (one < 32 || one == 127) {
System.out.println("Given value is a control character!");
} else {
System.out.println("Given value is not a control character!");
}
}
}輸出
Given value is a control character!
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP