java编写合并两个数组,{1,2,3,4,5} {4,5,6,7,8} 20
1个回答
展开全部
<pre t="code" l="java">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<number.length;i++){
for(int j = 0;j<number[i].length;j++){
newnumber[i][j] = number[j][i];
}
}
System.out.println("This is new Array");
for(int i = 0;i<number.length;i++){
for(int j = 0;j<number[i].length;j++){
System.out.print(newnumber[i][j]+" ");
}
System.out.println("");
}
System.out.println("This is old Array");
for(int i = 0;i<number.length;i++){
for(int j = 0;j<number[i].length;j++){
System.out.print(number[i][j]+" ");
}
System.out.println("");
}
int[][] newnumber = new int[number[0].length][number.length];
for(int i = 0;i<number.length;i++){
for(int j = 0;j<number[i].length;j++){
newnumber[i][j] = number[j][i];
}
}
System.out.println("This is new Array");
for(int i = 0;i<number.length;i++){
for(int j = 0;j<number[i].length;j++){
System.out.print(newnumber[i][j]+" ");
}
System.out.println("");
}
System.out.println("This is old Array");
for(int i = 0;i<number.length;i++){
for(int j = 0;j<number[i].length;j++){
System.out.print(number[i][j]+" ");
}
System.out.println("");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询