我写了下面的代码来遍历一个数组的一半对角线:
String[][] b = [a,b,c]
[d,e,f]
[g,h,i];
public void LoopDiag()
for (int i = b.length - 1; i > 0; i--) {
String temp = "";
for (int j = 0, x = i; x <= b.length - 1; j++, x++) {
temp = temp+b[x][j];
}
System.out.println(temp)
}
for (int i = 0; i <= b.length - 1; i++) {
String temp = "";
for (int j = 0, y = i; y <= b.length - 1; j++, y++) {
temp = temp+b[j][y];
}
System.out.println(temp);
}
}
现在它打印出对角线,即当前输出:
g dh aei bf c
我应该如何使其打印另一半的对角线,即所需输出:
a db gec hf i