anonymous
  • anonymous
How can i reverse both full diagonal rows(top left to bottom right and top right to bottom left) of a 2d array? (in java) eg 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96 to: 96 26 31 81 41 71 66 56 61 51 46 76 36 86 91 21
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
The other algorithm didn't work?
anonymous
  • anonymous
only reversed the corners, not the full diagonal row
anonymous
  • anonymous
Hmm, it works fine for me, testing it out with your values and different-sized arrays.
1 Attachment

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
hmmmmm, weird sorry. do you mind posting it again? (im on a different computer)
anonymous
  • anonymous
Sure, code is: /** * Method that inverts diagonals * * @param array */ public static void reverseDiagonals(int array[][]){ for(int i = 0; i < array.length / 2; i++){ // We only need to go through half the array int j = array[0].length - 1; // This variable will work the array backwards int temp = array[i][i]; // This will keep temporary value array[i][i] = array[j - i][j - i]; array[j - i][j - i] = temp; temp = array[i][j - i]; array[i][j - i] = array[j - i][i]; array[j - i][i] = temp; } }
anonymous
  • anonymous
thank you so much, very much appreciated (works of course)

Looking for something else?

Not the answer you are looking for? Search for more explanations.