on Leave a Comment

Java Program to Find ASCII value of a Character

ASCII(American Standard for Information Interchange) is a code to represent English characters using numeric code. It includes upper and lower case English letters, numbers and punctuation symbols. It assigns a number to each character from 0 to 127. For example ASCII code for alphabet A is 65. In Java, we can find ASCII value of character by assigning a character value to integer variable.

Java Program to Find ASCII Value of Character

public class ShowAscii {

    public static void main(String[] args) {

        char ch = 'A';
        int asciiCode = ch;
        // we can also cast char to int
        int castascii = (int)ch;

        System.out.println("ASCII value of "+ch+" is: " + asciiCode);
        System.out.println("ASCII value of "+ch+" is: " + castascii);
    }
}

Output:

ASCII value of A is: 65
ASCII value of A is: 65


0 comments:

Post a Comment