I wrote the following code to walk half the diagonals of an array:
String[][] b = [a,b,c]
[d,e,f]
[g,h,i];
public void LoopD
This is how:
int [][]mat = { {1,2,3},
{4,5,6},
{7,8,9},
};
int N=3;
for (int s=0; s-1; i--) {
System.out.print(mat[i][s-i] + " ");
}
System.out.println();
}
for (int s=1; s=s; i--) {
System.out.print(mat[i][s+N-1-i] + " ");
}
System.out.println();
}
The first loop prints the diagonals beginning from first column, the second loop prints the remaining diagonals (beginning from bottom row).
Output:
1
4 2
7 5 3
8 6
9