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