java编写合并两个数组,{1,2,3,4,5} {4,5,6,7,8}

2024年11月23日 07:03
有1个网友回答
网友(1):

int[][] number = {{1,2,3},{4,5,6},{7,8,9}};
int[][] newnumber = new int[number[0].length][number.length];
for(int i = 0;i for(int j = 0;j newnumber[i][j] = number[j][i];
}
}
System.out.println("This is new Array");
for(int i = 0;i for(int j = 0;j System.out.print(newnumber[i][j]+" ");
}
System.out.println("");
}
System.out.println("This is old Array");
for(int i = 0;i for(int j = 0;j System.out.print(number[i][j]+" ");
}
System.out.println("");
}