Friday, 10 April 2020

WAP in Java to accept an integer number & display its corresponding letter

WAP in Java to accept an integer number N such that 0<N<27 Display the corresponding letter of the alphabet 


import java.util.Scanner;
public class ATS{
public static void main(String[]args)
{
    Scanner in = new Scanner(System.in);
    System.out.print("Enter integer: ");
    int n = in.nextInt();
    if (n > 0 && n < 27)
    {
        char ch =(char)(n + 64);
        System.out.println("Corresponding letter = " + ch);       
    }
    else
    {
        System.out.println("Please enter a number in 1 to 26 range");       
    }

}
}

No comments:

Post a Comment