KnowledgeBoat Logo

Computer Applications

Write a program in Java to accept an integer number N such that 0<N<27. Display the corresponding letter of the alphabet (i.e. the letter at position N).
[Hint: If N =1 then display A]

Java

Java Library Classes

59 Likes

Answer

import java.util.Scanner;

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

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program in Java to accept an integer number N such that 0 N 27. Display the corresponding letter of the alphabet (i.e. the letter at position N). [Hint: If N =1 then display A]BlueJ output of Write a program in Java to accept an integer number N such that 0 N 27. Display the corresponding letter of the alphabet (i.e. the letter at position N). [Hint: If N =1 then display A]

Answered By

21 Likes


Related Questions