• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 22, 2022 |3.1K Views
Java Program to Find ASCII Value of a Char
  Share   Like
Description
Discussion


In this video, we will see the Java program to find ASCII value of a char. Each letter or number in the alphabet is assigned a unique code between 0 and 127. For example, 'A' is 65 and 'Z' is 90.

To find the ASCII value of a particular character, you just need to convert it to its decimal equivalent. For instance, the ASCII value of 'b' is 98, while the ASCII value of 'y' is 121.

Here we see two different method for find ASCII Value of a Char:
1.By assigning char to integer
2.By using Type Casting

By assigning char to integer:
In this approach, we generate the ASCII value of the given character with the help of a format specifier.We stored the value of the given character in a formal specifier specifying that the character is an int. Hence, the ASCII value of that character is stored inside the format specifier.

By using Type Casting:
Type-casting in java is a way to cast a variable into another datatype which means holding a value of another datatype occupying lesser bytes. In this approach, a character is a typecast of type char to the type int while printing, and it will print the ASCII value of the character.

Java Program to Print the ASCII Value: https://www.geeksforgeeks.org/java-program-to-print-the-ascii-value/

Read More