-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHourGlassPattern.java
More file actions
41 lines (38 loc) · 1.07 KB
/
Copy pathHourGlassPattern.java
File metadata and controls
41 lines (38 loc) · 1.07 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
import java.util.Scanner;
public class HourGlassPattern {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println();
int n, i, j;
System.out.print("Enter a number: ");
n = scan.nextInt();
for(i=0; i<=n; i++){
for(j=0; j<i;j++){
System.out.print(" ");
if(j>=1)
System.out.print(" ");
}
for(j=n-i;j>=0;j--){
System.out.print(j+" ");
}
for(j=1;j<=n-i;j++){
System.out.print(j+" ");
}
System.out.print("\n");
}
for(i=n-1; i>=0; i--){
for(j=0; j<i;j++){
System.out.print(" ");
if(j>=1)
System.out.print(" ");
}
for(j=n-i;j>=0;j--){
System.out.print(j+" ");
}
for(j=1;j<=n-i;j++){
System.out.print(j+" ");
}
System.out.print("\n");
}
}
}