ASCII Value

ASCII (American Standard Code for Information Interchange) is the character encoding standard of electronic communication. ASCII codes represent text within computers, telecommunications equipment, and other devices. – Wikipedia

Logic

To find ASCII value of a character we only have to cast them to integer data type. If the character is cast to integer data type then it automatically returns its ASCII value.

Casting is a way to convert a variable from one data type to another data type.

Program

import java.util.Scanner;

public class FindASCIIValue {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

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

        int asciiValue = (int) ch;

        System.out.printf("ASCII value of %c is %d\n", ch, asciiValue);
    }
}

Output

Enter any character : a
ASCII value of a is 97