Page 211 - Computer science 868 Class 12
P. 211
Program 11 Using switch case, print the following:
a. 4 3 2 1 b. A B C D E
3 2 1 A B C
2 1 A
1 A B C
A B C D E
1 import java.util.*;
2 class forloop_nested
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int ch,n,i,j,k=5;
8 double s=0,a;
9 System.out.println("1. pattern 1");
10 System.out.println("2. pattern 2 ");
11 System.out.println("Enter your choice ");
12 ch=sc.nextInt();
13 switch(ch)
14 {
15 case 1:
16 for(i=4;i>=1;i--)
17 {
18 for(j=i;j>=1;j--)
19 {
20 System.out.print(j+ " ");
21 }
22 System.out.println();
23 }
24 break;
25 case 2:
26 for(i=5;i>=1;i=i-1)
27 {
28 for(j=1;j<=k;j++)
29 {
209
Statements and Scope 209

