-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProblem_43.java
50 lines (46 loc) · 1.11 KB
/
Problem_43.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
/*
You need to take an integer input and then draw the pattern according to it. Say for example if you enter 5 then, the pattern should be like this-
0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
*/
import java.io.*;
import java.util.*;
public class Problem_43{
public static void main(String args[] ) throws Exception {
int n,z,w=1,o;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
z=n;
for(int i=0;i<n;i++){
z=1;
w=1;
o=i;
for(int j=0;j<n;j++){
if(z<n-i){
System.out.print(" ");
}else
{
System.out.print(o--);
if(i==0 && n!=1){
System.out.print(" ");
}
}
if(j!=n-1 ){
System.out.print(" ");
}
z++;
}
for(int k=0;k<i;k++){
if(k!=i){
System.out.print(" ");
}
System.out.print(w++);
}
if(i!=n-1)
System.out.println("");
}
}
}