-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP22_HollowSquarePattern.java
More file actions
39 lines (35 loc) · 1.09 KB
/
Copy pathP22_HollowSquarePattern.java
File metadata and controls
39 lines (35 loc) · 1.09 KB
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
package programs;
/**
* ============================================================
* PROGRAM 22: Hollow Square and Rectangle Patterns
* ============================================================
* Problem: WAP to print a Hollow Square and Hollow Rectangle pattern.
*
* Example (5 x 6):
* * * * * *
* * *
* * *
* * *
* * * * * *
* ============================================================
*/
public class P22_HollowSquarePattern {
public static void printHollowRectangle(int rows, int cols) {
System.out.printf("=== HOLLOW RECTANGLE (%d x %d) ===%n", rows, cols);
for (int r = 1; r <= rows; r++) {
for (int c = 1; c <= cols; c++) {
if (r == 1 || r == rows || c == 1 || c == cols) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
public static void main(String[] args) {
printHollowRectangle(5, 5);
System.out.println();
printHollowRectangle(4, 8);
}
}