Why isn't my 90 degree left array rotation code working?

  • Context: Comp Sci 
  • Thread starter Thread starter physicsfun
  • Start date Start date
  • Tags Tags
    Arrays Java Rotating
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
physicsfun
Messages
10
Reaction score
0

Homework Statement



Write code to rotate an array...

Homework Equations



why is this code not rotating my array 90 degrees to the left? thanks SO much in advance!

The Attempt at a Solution



public static int[][] rotateLeft(int[][] source) {
int[][] result = new int[source.length][source[0].length];
for (int i = 0; i < result.length; i++) {
for (int k = 0; k < result[0].length; k++) {
result[k] = source[source.length-1-i];}}
return result;}
 
Physics news on Phys.org
Do you see anything here:

Code:
result[i][k] = source[source.length-1-i][i];}}