Computer Applications

Using the switch-case statement, write a menu driven program to do the following:

(a) To generate and print Letters from A to Z and their Unicode

LettersUnicode
A65
B66
..
..
..
Z90

(b) Display the following pattern using iteration (looping) statement:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Java

Java Conditional Stmts

ICSE 2019

94 Likes

Answer

import java.util.Scanner;

public class KnowledgeBoat
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter 1 for letters and Unicode");
        System.out.println("Enter 2 to display the pattern");
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();
        switch(ch) {
            case 1:
            System.out.println("Letters\tUnicode");
            for (int i = 65; i <= 90; i++)
                System.out.println((char)i + "\t" + i);
            break;
            
            case 2:
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= i; j++)
                    System.out.print(j + " ");
                System.out.println();
            }
            break;
            
            default:
            System.out.println("Wrong choice");
            break;
        }
    }
}

Output

Answered By

41 Likes


Related Questions