Google News
logo
Java Program to Find ASCII Value of a Character
In the following example Java program to find the ASCII value of a character :
Program :
import java.util.Scanner;

public class AsciiValue {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a character: ");
        char ch = scanner.next().charAt(0);

        int asciiValue = ch;

        System.out.println("The ASCII value of " + ch + " is " + asciiValue);
    }
}
Output :
Enter a character: 18
The ASCII value of 1 is 49
In this program, we use the Scanner class to read a character input by the user. We then store the ASCII value of the character in an integer variable called asciiValue.

Finally, we print out the ASCII value of the character along with a message indicating which character's ASCII value was found.