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


ASCII 是美國資訊交換標準程式碼的縮寫。有 128 個標準 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

更新於: 13-03-2020

514 次瀏覽

開啟您的 事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.