-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
41 lines (36 loc) · 1.17 KB
/
Solution.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
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] matrix = new int[n][n];
int counter = 1;
int i=0,j=0;
for(i=0;i<n;i++)
{
if(j==n)
{
for(j=n-1;j>i-1;j--,counter++)
{
matrix[j][i]=counter;
}
}
else
{
for(j=i;j<n;j++,counter++)
{
matrix[j][i]=counter;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(matrix[i][j]!=0)
System.out.print(matrix[i][j]+" ");
}
System.out.println();
}
}
}