-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotMatrix.java
More file actions
55 lines (55 loc) · 1.11 KB
/
Copy pathRotMatrix.java
File metadata and controls
55 lines (55 loc) · 1.11 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
47
48
49
50
51
52
53
54
55
import java.util.*;
public class RotMatrix
{
int ary[][],m,n;
RotMatrix(int mm,int nn)
{
m=mm;
n=nn;
ary=new int [m][n];
}
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the elements");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
ary[i][j]=sc.nextInt();
}
}
}
RotMatrix rotate(RotMatrix A)
{
int k;
for(int c=0;c<n;c++)
{
k=m-1;
for(int r=0;r<m;r++)
{
ary[r][c]=A.ary[c][k];
k--;
}
}
return A;
}
void show()
{
System.out.println("Rotated Matrix: ");
for(int r=0;r<m;r++)
{
for(int c=0;c<n;c++)
System.out.print(ary[r][c]+"\t");
System.out.println();
}
}
static void main(int a,int b)
{
RotMatrix ob1=new RotMatrix(a,b);
RotMatrix ob2=new RotMatrix(b,a);
ob1.accept();
ob2.rotate(ob1);
ob2.show();
}
}