Java Program To Find ASCII Value Of Character
Chapter:
Miscellaneous
Last Updated:
25-08-2017 08:23:22 UTC
Program:
/* ............... START ............... */
public class JavaASCIIValueCharacter {
public static void main(String[] args) {
char ch = 'a';
int ascii = ch;
// You can also cast char to int
int castAscii = (int) ch;
System.out.println("The ASCII value of " + ch + " is: " + ascii);
System.out.println("The ASCII value of " + ch + " is: " + castAscii);
}
}
/* ............... END ............... */
Output
The ASCII value of a is: 97
The ASCII value of a is: 97
Notes:
-
ASCII abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices.
- In the above program for ASCII value of ch, we assign ch to an int variable ascii. Internally, Java converts the character value to an ASCII value.
- Casting converts from one type to another, here char variable ch is converted to an int variable castAscii.
Tags
Find ASCII Value Of Character, Java, Miscellaneous