-3
public class matrix
{
public static void main(String [] args)
{
int rows = 4;
int cols = 3;
int[][] result = new int[rows][];
for (int i = 0; i < rows; ++i)
result[i] = new int[cols];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(result[i][j] + " ");
}
System.out.print("\n");
}
}
}
我可以做同樣的事情,但對於行嗎?我想將新行添加到單個行矩陣。如何將新行添加到現有矩陣?
你可以使用'''矢量'''而不是陣列。在javadoc中閱讀它,並在谷歌搜索一些教程,這很簡單 – Hagai 2014-11-05 18:19:50