write pattern program using switch case in java
i-54321
5432
543
54
5
ii-AAAAA
BBBB
CCC
DD
E
Answers
Question:-
- write pattern program using switch case in java
54321
5432
543
54
5
AAAAA
BBBB
CCC
DD
E
Answer:-
//CODE WRITTEN BY @swetank232894
import java.util.*;
class Code
{
public static void main (String ar[])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter 1 for Pattern 1 and 2 for Pattern 2");
int ch=sc.nextInt();
switch (ch)
{
case 1: for(I=1;I<=5;I++)
{
for(j=5;j>=I;j--)
{
System.out.print(j);
}
System.out.println();
}
break;
case 2: for(I=65;I<=69;I++)
{
for(j=69;j>=I;j--)
{
System.out.print((char)(I));
}
System.out.println();
}
break;
default: System.out.println("Wrong Input");
}
//end of switch block
}//end of main()
}//end of class