-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern1.java
39 lines (35 loc) · 845 Bytes
/
Pattern1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* print the following pattern for N rows:
For N=4:
****
****
****
****
*/
package Patterns;
import java.util.Scanner;
public class Pattern1 {
public static void main(String[] args) {
System.out.print("Enter the number of rows n = ");
Scanner sc = new Scanner(System.in);
// Take user input, n = Number of Rows
int n = sc.nextInt();
// The loop starts with the 1st row
int row = 1;
// Loop will on for N rows
while(row<=n) {
// loop starts with the first column in the current row
int column = 1;
//Loop will on for N columns
while(column<=n) {
// printing (*) in each column
System.out.print("*");
//Increment the current column (Inner Loop)
column = column+1;
}
// Increment the current row (Outer Loop)
row = row+1;
// Add a new Line after each row
System.out.println();
}
}
}