0

How to write a menu driven program to print the design according to users choice

(a)1 2 3 4 5 (b) 5 5 5 5 5 1 2 3 4 4 4 4 4 1 2 3 3 3 3 1 2 2 2 1 1

2nd Dec 2018, 3:18 AM
Abha Singh
Abha Singh - avatar
1 Antwort
+ 2
Hi mam....you can use switch case for menu driven program import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.println("enter 1 for first pattern, enter 2 for second pattern, and enter 3 for exit"); for(;;) { System.out.print("enter your choice : "); int choice=input.nextInt(); switch(choice) { case 1:for(int i=5;i>=1;i--) { for(int j=1;j<=i;j++) { System.out.print(j); } System.out.println(); } break; case 2:for(int i=5;i>=1;i--) { for(int j=1;j<=i;j++) { System.out.print(i); } System.out.println(); } break; case 3:System.exit(0); break; default:System.out.println("invalid choice"); } } } }
2nd Dec 2018, 3:43 AM
Rishi Anand
Rishi Anand - avatar