Find ASCII Value of a Character
Read a character and print its ASCII value.
BeginnerTopic: Module 1: Basic Java Programs
Java Find ASCII Value of a Character Program
This program helps you to learn the fundamental structure and syntax of Java programming.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = sc.next().charAt(0);
int ascii = (int) ch;
System.out.println("ASCII value of " + ch + " = " + ascii);
sc.close();
}
}Output
Enter a character: A ASCII value of A = 65
Understanding Find ASCII Value of a Character
In Java, char is internally stored as a number (Unicode code point).
Casting the char to int reveals its numeric ASCII/Unicode value.
Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.