Java Program to find ASCII value of a character


In this program, You will learn how to find ASCII value of a character in Java.


char ch = 'B';

66 = (int) ch;


Example: How to find ASCII value of a character in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        char ch;
        int asc;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a Character Value :");
        ch = sc.next().charAt(0);

        asc = (int)ch;

        System.out.println("\nASCII Value is :" + asc);

    }
}

Output:

Enter a Character Value :B
ASCII Value is :66