Java program to print alphabets using ascii values

Let’s learn java program to print alphabets using ascii values.

Java program to print alphabets using ascii values

To print a to z in java using ascii value we have to type cast.

Here casting means converting variable from one type to another.

But internally java converts character value to ascii value.

In the below java program we are converting char variable to integer variable.

public class PrintAlphabetUsingAscii 
{
   public static void main(String[] args) 
   {
      char ch = 'B';
      int ascii = ch;
      int castAscii = (int) ch;   
      System.out.println("ascii value of " + ch + " is: " + ascii);
      System.out.println("ascii value of " + ch + " is: " + castAscii);
   }
}


Output:

ascii value of B is: 66
ascii value of B is: 66


Also read – polymorphism in java