-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare_Hollow_Pattern.java
More file actions
35 lines (32 loc) · 998 Bytes
/
Copy pathSquare_Hollow_Pattern.java
File metadata and controls
35 lines (32 loc) · 998 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
29
30
31
32
33
34
35
// Java Program to print pattern
// Square hollow pattern
import java.util.*;
class Square_Hollow_Pattern {
// Function to demonstrate 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
|| 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 = 6;
printPattern(n);
}
}