1.

Write a menu driven program to display the pattern as per user’s choice.Pattern 1Pattern 2ABCDEBABCDLLABCUUUABEEEEAFor an incorrect option, an appropriate error message should be displayed.

Answer»

import java.io.*; 

import java.util.Scanner; 

class Pattern { 

public static void main(String args[]) throws IOException { 

Scanner sc = new Scanner(System.in); 

System.out.println(“::::MENU::::”) 

System.out.println(” 1. To display ABCD Pattern”); 

System.out.print(” 2. To display Word Pattern”); 

System.out.print(“Enter your choice:”); 

int ch= sc.nextlnt(); 

switch(ch) { 

case 1: for (char i = ‘E’; i > = ‘A’; i- -){

for(char j = ‘A’;j <=i;j + +){ 

System.out.print(j); 

System.out.prindn( ); 

break; case 2: 

String S = “BLUE”; 

for (int i = 0; i < S.length(); i+ +) 

{ for(int j = 0; j < =i; j + +) 

{ System.out.print(S.charAt(i)); 

} System.out.println(); 

break; default: 

System.out.println(“Invalid Input”); break; 

}



Discussion

No Comment Found

Related InterviewSolutions