KnowledgeBoat Logo

Computer Applications

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

Java

Java Library Classes

84 Likes

Answer

import java.util.Scanner;

public class KboatASCIIReverse
{
   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);
   }
}

Variable Description Table

Program Explanation

Output

BlueJ output of 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

Answered By

30 Likes


Related Questions