-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHollow_Hourglass_Pattern.java
More file actions
54 lines (48 loc) · 1.48 KB
/
Copy pathHollow_Hourglass_Pattern.java
File metadata and controls
54 lines (48 loc) · 1.48 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Java Program to print pattern
// Hollow Hourglass Pattern
import java.util.*;
class Hollow_Hourglass_Pattern {
// Function to demonstrate pattern
public static void printPattern(int n)
{
int i, j;
// Printing the upper part
for (i = 1; i <= n; i++) {
// inner loop to print spaces.
for (j = 1; j < i; j++) {
System.out.print(" ");
}
// inner loop to print value of j.
for (j = i; j <= n; j++) {
if(j==i||j==n||i==1)
System.out.print("* ");
else
System.out.print(" ");
}
// printing new line for each row
System.out.println();
}
// Printing the lower part
for (i = n - 1; i >= 1; i--) {
// inner loop to print spaces.
for (j = 1; j < i; j++) {
System.out.print(" ");
}
// inner loop to print value of j.
for (j = i; j <= n; j++) {
if(j==i||j==n||i==1)
System.out.print("* ");
else
System.out.print(" ");
}
// printing new line for each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 6;
printPattern(n);
}
}