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!

更新時間:6月26日,2020

233 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.