Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

scherniak Group Title

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

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Narsat Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    The other algorithm didn't work?

    • 2 years ago
  2. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    only reversed the corners, not the full diagonal row

    • 2 years ago
  3. Narsat Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Hmm, it works fine for me, testing it out with your values and different-sized arrays.

    • 2 years ago
    1 Attachment
  4. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    hmmmmm, weird sorry. do you mind posting it again? (im on a different computer)

    • 2 years ago
  5. Narsat Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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; } }

    • 2 years ago
  6. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    thank you so much, very much appreciated (works of course)

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.