Tuesday, 21 April 2020

Write a program to input a letter. Find its ASCII code. Reverse the ASCII code and display the equivalent character.

Sample Input: Y
Sample Output: ASCII Code = 89
 Reverse the code = 98
 Equivalent character: b



public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a letter: ");
char l = in.next().charAt(0);
int a = (int)l;
System.out.println("ASCII Code = " + a);
int r = 0;
while (a > 0)
{
int digit = a % 10;           
r = r * 10 + digit;           
a /= 10;       
}
System.out.println("Reversed Code = " + r);
System.out.println("Equivalent character = " + (char)r);
    }
}

No comments:

Post a Comment