11. Write a program in Java to display the following patterns using menu driven program with switch case:
(i) A
ab
ABC
abcd
ABCDE
Answers
Answered by
2
Answer:
Step-by-step explanation:
Sample Program:
import java. util. *;
class brainly
{
public static void main(String args[])
{
System. out. println("Enter your choice : 1 (or) 2);
Scanner demo = new S canner(System. in);
int a = demo. nextInt();
System. out. println();
switch(a)
{
case 1:
int i,j;
for(i = 1; i <=5; i++)
{
for(j = 1; j<=5 - i + 1;j++)
{
System. out. print((char)(j+64));
}
System. out. println("");
}
break;
case 2:
String str="BLUEJ";
for(i = 0 ; i < str. length () - 1 ; i++)
{
for(j = str. length() ; j>i ; j--)
{
System. out. print("");
}
for(int k = 0; k <=i; k++)
{
System. out. print(str. charAt(i));
}
System. out. print("\n");
}
break;
default:
System. out. println("wrong choice");
}
}
}
Output:
Enter your choice: 1 (or) 2
1
ABCDE
ABCD
ABC
AB
A
Attachments:
Similar questions
Economy,
5 months ago
Sociology,
5 months ago
Political Science,
10 months ago
Math,
10 months ago
Social Sciences,
1 year ago