C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Menu Driven Program - Java Programs

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

 

import java.util.Scanner; class Menu{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("1. Unicode"); System.out.println("2. Pattern"); System.out.print("Enter your choice: "); int choice = Integer.parseInt(in.nextLine()); switch(choice){ case 1: System.out.println("Letters\tUnicode"); for(char i = 'A'; i <= 'Z'; i++) System.out.println(i + "\t" + (int)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("Invalid choice!"); } } }

Output

 
 OUTPUT 1: 
1. Unicode
2. 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 

 OUTPUT 2: 
1. Unicode
2. Pattern
Enter your choice: 2
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5