-7

I´m trying to reverse a Diagonal of a matrix in java! I've done everything but nothing works.

Please see the image below so you can understand the question!!!
enter image description here

Andreas
  • 154,647
  • 11
  • 152
  • 247
Falco
  • 1
  • 2
  • Welcome to stackoverflow. Please read [How to ask a good question](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve), before posting a question. – vinS Dec 11 '17 at 05:15
  • If you have broken code please read [mcve] and enhance your question accordingly. – GhostCat Dec 11 '17 at 05:15

1 Answers1

1

Following code snippet will reverse the diagonal as per your need. See the complete working program here:

static void reverseDiagonal(char[][] iArray)
{
    final int SIZE = iArray[0].length;
    final int len = SIZE/2;
    for(int i=0; i< len; i++)
    {
        final int j = i+1;
        char tTemp = iArray[i][i];
        iArray[i][i] = iArray[SIZE-j][SIZE-j];
        iArray[SIZE-j][SIZE-j] = tTemp;
        
        tTemp = iArray[i][SIZE-j];
        iArray[i][SIZE-j] = iArray[SIZE-j][i];
        iArray[SIZE-j][i] = tTemp;
    }
}
cse
  • 4,066
  • 2
  • 20
  • 37