Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Rotate matrix clockwise
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; //Rotate nXn 2D matrix by 90degrees class Rextester { public static void main(String args[]) { System.out.println("Hello, World!"); } public static void rotate(int[][] matrix) { //1. Rows become columns //2. First column becomes last column & so on. //[]i,j] to [j,i] for(int i = 0;i<matrix.length;i++){ for(int j =i;j<matrix[0].length;j++){ int tmp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = tmp; } } int n = matrix.length; //up is down for(int i = 0;i<matrix.length;i++){ for(int j = 0;j<matrix[0].length/2;j++){ int tmp = matrix[i][n-j-1]; matrix[i][n-j-1] = matrix[i][j]; matrix[i][j] = tmp; } } } }
run
|
edit
|
history
|
help
0
mango
Votes JAVA
3.A
JAVA # Klavyeden Girilen cümlelerin en uzununu bulma
PE #12
test1
1
Strotium no.
java.
Sorted Array