一個列印特定字元的 ASCII 值的 Java 程式


ASCII 是美國標準資訊交換碼的縮寫。有 128 個標準的 ASCII 碼,每個 ASCII 碼都可以用一個 7 位的二進位制數(0000000 到 1111111)表示。

如果嘗試將字元儲存到整數中,它會儲存相應字元的 ASCII 值。

示例

import java.util.Scanner;
public class ASCIIValue {
   public static void main(String args[]){
      System.out.println("Enter a character ::");
      Scanner sc = new Scanner(System.in);
      char ch = sc.next().charAt(0);
      int asciiValue = ch;
      System.out.println("ASCII value of the given character is ::"+asciiValue);
   }
}

輸出

Enter a character ::
e
ASCII value of the given character is ::101

更新時間:2020 年 3 月 13 日

514 次瀏覽

開啟職業生涯 新篇章

完成課程即可獲得認證

開始行動
廣告
© . All rights reserved.