Using the switch-case statement, write a menu driven program to do the following:
Java Programming Language (Article) (Program)
6
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
Letters | Unicode |
---|---|
A | 65 |
B | 66 |
. | . |
. | . |
. | . |
Z | 90 |
(b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program:
import java.util.Scanner; public class RAnsariSwitchCase { 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:
Enter 1 for letters and Unicode Enter 2 to display the pattern Enter your choice: 1 Letters Unicode A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79 P 80 Q 81 R 82 S 83 T 84 U 85 V 86 W 87 X 88 Y 89 Z 90 Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.