Skip to content

Commit

Permalink
Create rotate180
Browse files Browse the repository at this point in the history
using java by chhavi
  • Loading branch information
Chhavi07-arch authored and x0lg0n committed Oct 31, 2024
1 parent 69c6896 commit 10396f9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Java/rotate180
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class rotate180d{
static void rotateMatrix(int[][] mat){
int n=mat.length;
int [][] res= new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
res[i][j]=mat[n-i-1][n-j-1];
}
}
for(int i = 0; i < n; i++){
System.arraycopy(res[i], 0, mat[i], 0, n);
}
}
public static void main(String[] args) {
int[][] mat = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

rotateMatrix(mat);

// Print the rotated matrix
for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat[i].length; j++) {
System.out.print(mat[i][j] + " ");
}
System.out.println();
}
}


}

0 comments on commit 10396f9

Please sign in to comment.