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

2024-11-23 07:03:53
推荐回答(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("");
}