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