Formatted with Google Java Formatter
This commit is contained in:
parent
dc2d3d3ff8
commit
e72d71c0d7
@ -1,12 +1,9 @@
|
|||||||
package Others;
|
package Others;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a matrix of size n x n
|
* Given a matrix of size n x n We have to rotate this matrix by 90 Degree Here is the algorithm for
|
||||||
* We have to rotate this matrix by 90 Degree
|
* this problem .
|
||||||
* Here is the algorithm for this problem .
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
class Rotate_by_90_degree {
|
class Rotate_by_90_degree {
|
||||||
@ -18,31 +15,24 @@ class Rotate_by_90_degree {
|
|||||||
int n = sc.nextInt();
|
int n = sc.nextInt();
|
||||||
int[][] arr = new int[n][n];
|
int[][] arr = new int[n][n];
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) arr[i][j] = sc.nextInt();
|
||||||
for (int j = 0; j < n; j++)
|
|
||||||
arr[i][j] = sc.nextInt();
|
|
||||||
|
|
||||||
Rotate g = new Rotate();
|
Rotate g = new Rotate();
|
||||||
g.rotate(arr);
|
g.rotate(arr);
|
||||||
printMatrix(arr);
|
printMatrix(arr);
|
||||||
|
|
||||||
}
|
}
|
||||||
sc.close();
|
sc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printMatrix(int arr[][]) {
|
static void printMatrix(int arr[][]) {
|
||||||
for (int i = 0; i < arr.length; i++) {
|
for (int i = 0; i < arr.length; i++) {
|
||||||
for (int j = 0; j < arr[0].length; j++)
|
for (int j = 0; j < arr[0].length; j++) System.out.print(arr[i][j] + " ");
|
||||||
System.out.print(arr[i][j] + " ");
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Class containing the algo to roate matrix by 90 degree */
|
||||||
* Class containing the algo to roate matrix by 90 degree
|
|
||||||
*/
|
|
||||||
|
|
||||||
class Rotate {
|
class Rotate {
|
||||||
static void rotate(int a[][]) {
|
static void rotate(int a[][]) {
|
||||||
int n = a.length;
|
int n = a.length;
|
||||||
@ -66,6 +56,5 @@ class Rotate {
|
|||||||
i++;
|
i++;
|
||||||
k--;
|
k--;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user