Java 程式檢查字元是否為 7 位 ASCII 碼
檢查字元是否為 7 位 ASCII 碼,檢查給定值的 ASCII 值是否小於 128。
這裡我們有一個字元。
char one = '-';
現在,我們藉助 if-else 語句檢查了 7 位 ASCII 碼字元的條件。
if (c < 128) { System.out.println("Given value is ASCII 7 bit!"); } else { System.out.println("Given value is not an ASCII 7 bit!"); }
以下是在其中檢查字元的 7 位 ASCII 碼的示例。
示例
public class Demo { public static void main(String []args) { char c = '-'; System.out.println("Given value = "+c); if ( c < 128) { System.out.println("Given value is ASCII 7 bit!"); } else { System.out.println("Given value is not an ASCII 7 bit!"); } } }
輸出
Given value = * Given value is ASCII 7 bit!
我們來看看一個示例,其中我們有一個字元,並檢查輸入的值是否為 7 位 ASCII 碼。
示例
public class Demo { public static void main(String []args) { char c = 'u'; System.out.println("Given value = "+c); if ( c < 128) { System.out.println("Given value is ASCII 7 bit!"); } else { System.out.println("Given value is not an ASCII 7 bit!"); } } }
輸出
Given value = u Given value is ASCII 7 bit!
廣告