Page 205 - Cs_withBlue_J_C11_Flipbook
P. 205
22 System.out.print("*");
23 }
24 System.out.println("");
25 }
26 break;
27 case 2:
28 System.out.println("Enter the number of rows: ");
29 rows = sc.nextInt();
30 for (i= 0; i<= rows-1; i++) {
31 for (j=0; j<=i; j++) {
32 System.out.print(" ");
33 }
34 for (k=0; k<=rows-1-i; k++)
35 {
36 System.out.print("*" + " ");
37 }
38 System.out.println();
39 }
40 break;
41 default: System.out.println("Wrong Choice");
42 }
43 }
44 }
The output of the preceding program is as follows:
1. Pattern 1
2. Pattern 2
Enter your choice
1
Enter number of rows:
5
*
**
***
****
*****
203
Statements and Scope 203

