Computer Science, asked by SƬᏗᏒᏇᏗƦƦᎥᎧƦ, 2 months ago

_______________________
Write a menu driven program to display the pattern as per user's choice:

Pattern 1
ABCDE
ABCD
ABC
AB
A


Pattern 2
B
LL
UUU
EEE
________________________

Note:
Don't spam ​

Answers

Answered by itztalentedprincess
17

Question:

Write a menu driven program to display the pattern as per user's choice:

Pattern 1

ABCDE

ABCD

ABC

AB

A

Pattern 2

B

LL

UUU

EEE

Answer:

import java.util.Scanner;

public class KboatMenuPattern

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Enter 1 for pattern 1");

System.out.println("Enter 2 for Pattern 2");

System.out.print("Enter your choice: ");

int choice = in.nextInt();

switch (choice) {

case 1:

for (int i = 69; i >= 65; i--) {

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

System.out.print((char)j);

}

System.out.println();

}

break;

case 2:

String word = "BLUE";

int len = word.length();

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

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

System.out.print(word.charAt(i));

}

System.out.println();

}

break;

default:

System.out.println("Incorrect choice");

break;

Answered by Oreki
4

\textsf{\large \textbf{Algorithm}}

   \text{\textemdash \:\: Getting the users choice using the \textbf{Scanner} class.}\\\text{\textemdash \:\: Made discrete methods for the patterns.}\\\text{\textemdash \:\: Calling the methods in the suitable switch case.}\\\text{\textemdash \:\: Displaying the selected pattern on the screen.}

Attachments:
Similar questions