Java Program to find the ASCII value of a character


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


char ch = 'B';

66 = (int) ch;

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

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("ASCII value is:" + asc);

    }
}

Output:

Enter a character value:H
ASCII value is:72