-
Notifications
You must be signed in to change notification settings - Fork 0
/
FanPattern.java
57 lines (53 loc) · 1.34 KB
/
FanPattern.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* this program will print fan pattern
input :
7
output :
1 * * * * * * 7 6 5 4 3 2 1
2 1 * * * * * 6 5 4 3 2 1 *
3 2 1 * * * * 5 4 3 2 1 * *
4 3 2 1 * * * 4 3 2 1 * * *
5 4 3 2 1 * * 3 2 1 * * * *
6 5 4 3 2 1 * 2 1 * * * * *
7 6 5 4 3 2 1 1 * * * * * *
* * * * * * 1 7 6 5 4 3 2 1
* * * * * 2 1 * 6 5 4 3 2 1
* * * * 3 2 1 * * 5 4 3 2 1
* * * 4 3 2 1 * * * 4 3 2 1
* * 5 4 3 2 1 * * * * 3 2 1
* 6 5 4 3 2 1 * * * * * 2 1
7 6 5 4 3 2 1 * * * * * * 1
*/
import java.util.*;
public class Hello {
public static void main(String[] args) {
int n = new Scanner(System.in).nextInt(), count=1, m=n;
for(int i=1; i<=n; i++){
int temp=count++;
int temp1=m--;
for(int j=1; j<=n; j++){
if(j<=i) System.out.print((temp--)+" ");
else System.out.print("* ");
}
for(int j=n; j>0; j--){
if(j>=i) System.out.print((temp1--)+" ");
else System.out.print("* ");
}
System.out.println();
}
count=1;
m=n;
for(int i=1; i<=n; i++){
int temp1=count++;
int temp2=m--;
for(int j=1; j<=n; j++){
if(j>n-i) System.out.print((temp1--)+" ");
else System.out.print("* ");
}
for(int j=1; j<=n; j++){
if(j>=i) System.out.print((temp2--)+" ");
else System.out.print("* ");
}
System.out.println();
}
}
}