-
Notifications
You must be signed in to change notification settings - Fork 0
/
InnerReducingPattern.java
53 lines (40 loc) · 1.09 KB
/
InnerReducingPattern.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
/*******************************************************************************
Inner reducing pattern
input: 4
output:
4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n=x.nextInt(),t=n,k=0;
System.out.println();
for(int i=0;i<n;i++){
t=n;
for(int j=0;j<i;j++) System.out.print((t--)+" ");
for(int j=0;j<n+n-1-(i+i);j++) System.out.print((n-k)+" ");
t++;
for(int j=0;j<i;j++) System.out.print((t++)+" ");
System.out.println();
k++;
}
k--;
for(int i=n-2;i>=0;i--){
t=n;
for(int j=0;j<i;j++) System.out.print((t--)+" ");
for(int j=0;j<n+n-1-(i+i);j++) System.out.print((n-k+1)+" ");
t++;
for(int j=0;j<i;j++) System.out.print((t--)+" ");
System.out.println();
k--;
}
}
}