1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Rotating arrays in java

  1. Mar 9, 2009 #1
    1. The problem statement, all variables and given/known data

    Write code to rotate an array...

    2. Relevant equations

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

    3. 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;}
     
  2. jcsd
  3. Mar 9, 2009 #2
    Do you see anything here:

    Code (Text):
    result[i][k] = source[source.length-1-i][i];}}
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook