Rotate array clockwise
- by user69514
I have a two dimensional array that I need to rotate 90 degrees clockwise, however I keep getting arrayindexoutofbounds...
public int[][] rorateArray(int[][] arr){
//first change the dimensions vertical length for horizontal length
//and viceversa
int[][] newArray = new int[arr[0].length][arr.length];
//invert values 90 degrees clockwise by starting from button of
//array to top and from left to right
int ii = 0;
int jj = 0;
for(int i=0; i<arr[0].length; i++){
for(int j=arr.length-1; j>=0; j--){
newArray[ii][jj] = arr[i][j];
jj++;
}
ii++;
}
return newArray;
}