forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.java
36 lines (34 loc) · 796 Bytes
/
rectangle.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
// Java Program to print pattern
// Square hollow pattern
import java.util.*;
public class GeeksForGeeks {
// 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);
}
}