-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiamond+Pascal_Pattern.java
62 lines (58 loc) · 1.08 KB
/
Diamond+Pascal_Pattern.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
package technicals;
import java.util.*;
public class Pattern {
static void pattern(int n)
{
for(int i =1;i<=2*n-1;i++)
{
if(i<=n)
{
for(int k =1;k<=n-i;k++)
{
System.out.print(" ");
}
for(int j =i;j>=1;j--)//for printing the left side of the column i.e. i to 1
{
System.out.print(j+" ");
}
for(int j =2;j<=i;j++)//for printing the right side of the column i.e. 2 to i
{
System.out.print(j+" ");
}
}
else
{
for(int k =1;k<=i-n;k++)
{
System.out.print(" ");
}
for(int j =n-(i-n);j>=1;j--)//for printing the left side of the column i.e. i to 1
{
System.out.print(j+" ");
}
for(int j =2;j<=n-(i-n);j++)//for printing the right side of the column i.e. 2 to i
{
System.out.print(j+" ");
}
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
pattern(n);
}
}
/*
5
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
4 3 2 1 2 3 4
3 2 1 2 3
2 1 2
1
*/