下面是代码,我只是想知道其他人是否对它进行了不同的编码。也许我可以做些小改动。提前致谢!
public class addRow {
public static int[][] insert(int [][] a, int [] row, int index){
int [][] x = new int[a.length+1][a.length];
int [] temp;
for(int i=0; i<x.length-1; i++)
{
x[i] = a[i];
if(i == index)
{
temp = a[i];
x[i] = row;
x[i+1] = temp;
}
}
return x;
}
public static void main(String[] args){
int[][] a = {{1,2,3},{4,5,6},{10,11,12}};
int[] row = {7,8,9};
int [][] b = insert(a,row ,2);
for(int r=0; r < b.length; r++){
for(int c=0;c< b[r].length; c++){
System.out.print(b[r][c] + " ");
}System.out.println();
}
}
}