public class TestMain {
int[][] rr = new int[][]{
{0, 5, 6, 9},
{3, 0, 1, 3},
{8, 1, 0, 2},
{9, 2, 4, 0}};
public TestMain() {
getHalfMatrix(rr);
}
public void getHalfMatrix(int[][] mrix) {
int st = (int) mrix.length/2;
System.out.print("Matrix1\n");
for (int i = 0; i < st; i++) {
for (int j = 0; j < mrix[0].length; j++) {
System.out.print("\t" + mrix[i][j]);
}
System.out.print("\n");
}
System.out.print("Matrix2\n");
for (int i = st; i < mrix.length; i++) {
for (int j = 0; j < mrix[0].length; j++) {
System.out.print("\t" + mrix[i][j]);
}
System.out.print("\n");
}
}
public static void main(String[] args) {
new TestMain();
}
}
輸出是:
Matrix1
0 5 6 9
3 0 1 3
Matrix2
8 1 0 2
9 2 4 0
你嘗試過這麼遠嗎? – QBrute
什麼是打印矩陣1的邏輯? –
它是否必須是明確的?矩陣如何存儲? – harold