forked from namigoel/hacktober-coding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotate90.java
More file actions
46 lines (44 loc) · 1.26 KB
/
Copy pathRotate90.java
File metadata and controls
46 lines (44 loc) · 1.26 KB
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
import java.util.*;
class Rotate90
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Input the number of rows or columns in the matrix");
int m=sc.nextInt();
if(m>=2&&m<=20)
{
int a[][]=new int[m][m];
System.out.println("Input the elements in the matrix");
for(int x=0;x<m;x++)
{
for(int y=0;y<m;y++)
{
a[x][y]=sc.nextInt();
}
}
System.out.println("The original matrix is-");
for(int x=0;x<m;x++)
{
for(int y=0;y<m;y++)
{
System.out.print(a[x][y]+"\t");
}
System.out.println();
}
int b[][]=new int[m][m];
System.out.println("The rotated matrix is-");
for(int x=0;x<m;x++)
{
for(int y=0;y<m;y++)
{
b[x][y]=a[m-y-1][x];
System.out.print(b[x][y]+" \t");
}
System.out.println();
}
}
else
System.out.println("Size out of range");
}
}