-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberpattern3.java
More file actions
40 lines (36 loc) · 964 Bytes
/
numberpattern3.java
File metadata and controls
40 lines (36 loc) · 964 Bytes
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
import java.util.Scanner;
public class Runner {
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
int n = s.nextInt();
Solution.printPattern(n);
}
}
public class Solution {
public static void printPattern(int n){
int i,j,k;
for(i = -(n-1); i < n; i++){
j = n;
for(k = -(n-1); k < n; k++){
if(Math.abs(i) < Math.abs(k))
{
if(k < 0)
{
System.out.print(j+" ");
j--;
}
else
{
j++;
System.out.print(j+" ");
}
}
else
{
System.out.print(j+" ");
}
}
System.out.println();
}
}
}