-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate90.java
More file actions
41 lines (38 loc) · 1.18 KB
/
Copy pathrotate90.java
File metadata and controls
41 lines (38 loc) · 1.18 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
package matrix;
import java.util.Scanner;
public class rotate90 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n;
System.out.println("enter the number of rows and column : ");
n = s.nextInt();
int ar[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.println("enter the element : " + i + " " + j);
ar[i][j] = s.nextInt();
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(ar[i][j]);
}
System.out.println();
}
System.out.println();
//transpose of matrix
int ar2[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ar2[j][i] = ar[i][j];
}
}
//print the output
for (int i = 0; i < n; i++) {
for (int j = n - 1; j >= 0; j--) {
System.out.print(ar2[i][j]);
}
System.out.println();
}
}
}