Page 204 - Cs_withBlue_J_C11_Flipbook
P. 204
The output of the preceding program is as follows:
1. Pattern 1
2. Pattern 2
Enter your choice
1
1
1 2
1 2 3
1 2 3 4
Program 13 Write a Java program to print the following using switch case statement.
1. * 2. * * * * *
** * * * *
*** * * *
**** * *
***** *
******
1 import java.util.*;
2 class nestedloop2
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int ch, i, j, k, rows;
8 System.out.println("1. Pattern 1");
9 System.out.println("2. Pattern 2 ");
10 System.out.println("Enter your choice ");
11 ch=sc.nextInt();
12 switch(ch)
13 {
14 case 1:
15 System.out.println("Enter number of rows: "); // takes input from user
16 rows = sc.nextInt();
17 for (i= 0; i<= rows; i++) {
18 for (j=1; j<=rows-i; j++) {
19 System.out.print(" ");
20 }
21 for (k=0; k<=i-1; k++) {
202202 Touchpad Computer Science-XI

