-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.java
More file actions
28 lines (27 loc) · 854 Bytes
/
Copy pathpattern.java
File metadata and controls
28 lines (27 loc) · 854 Bytes
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
public class pattern {
public static void printPattern(int n) {
int i, j;
// outer loop to handle number of rows
for (i = 0; i < n; i++) {
// inner loop to handle number of columns
for (j = 0; j < n; j++) {
// star will print only when it is in first
// row or last row or first column or last
// column
if (i == 0 || j == 0 || i == (n - 1) / 2 || j == n - 1) {
System.out.print("*");
}
// otherwise print space only.
else {
System.out.print(" ");
}
}
System.out.println();
}
}
// Driver Function
public static void main(String args[]) {
int n = 4;
printPattern(n);
}
}