Page 261 - CA_Blue( J )_Class9
P. 261
Write a program to draw the following pattern:
Program 16
****1
***2
**3
*4
5
1 import java.util.*;
2 public class number_star_pattern
3 {
4 public static void main(String args[])
5 {
6 Scanner input = new Scanner(System.in);
7 System.out.println ("Please enter number of rows: ");
8 int rows = input.nextInt();
9 for (int i = 1; i <= rows; i++)
10 {
11 for (int j = i; j <= rows; j++)
12 {
13 if (j == rows)
14 System.out.print(i + " ");
15 else
16 System.out.print("* ");
17 }
18 System.out.println();
19 }
20 }
21 }
You will get the following output:
Nested Loop 259

