-
Notifications
You must be signed in to change notification settings - Fork 1
/
PatternC.java
97 lines (96 loc) · 1.2 KB
/
PatternC.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.io.*;
import java.util.*;
class PatternC
{
public static void main(String[]args)
{
Scanner venki=new Scanner(System.in);
int n=venki.nextInt();
int i,j,C=n,k=0,x=0,c=0,N=0;
N=2*n-1;
x=((2*n-1)/2)+2;
for(i=0;i<2*n-1;i++)
{
k=N;
C=n;
c++;
if(c==x)
{
break;
}
for(j=0;j<2*n-1;j++)
{
if(i==j)
{
while(k!=0)
{
System.out.print(C+" ");
k--;
}
}
else if(k!=0)
{
System.out.print(C+" ");
C--;
}
else if(k==0 && C==n)
{
break;
}
else //(k==0)
{
C++;
System.out.print(C+" ");
if(C==n)
break;
}
}
N=N-2;
System.out.println();
}
x--;
C=0;
c=0;
N=2*n-1;
int s=n-x;
int m=((2*n-1)/2)-1;
N=3;
for(i=0;i<2*n-1;i++)
{
c=n;
k=N;
C++;
if(C==x)
{
break;
}
for(j=0;j<2*n-1;j++)
{
if((i+j)==m)
{
while(k!=0)
{
System.out.print(c+" ");
k--;
}
}
else if(k==0 && c==n)
{
break;
}
else if(k==0)
{
c++;
System.out.print(c+" ");
}
else if(k!=0)
{
System.out.print(c+" ");
c--;
}
}
N=N+2;
System.out.println();
}
}
}