数组1 数组2
1 2 6 8 7 1 4 0 5 9
4 8 6 0 1 2 8 1 2 2
0 1 2 4 0 对角线互换后 6 6 2 1 6
5 2 1 8 2 8 0 4 8 8
9 2 6 8 7 7 1 0 2 7
怎么写代码实现上面的效果?
1 2 6 8 7 1 4 0 5 9
4 8 6 0 1 2 8 1 2 2
0 1 2 4 0 对角线互换后 6 6 2 1 6
5 2 1 8 2 8 0 4 8 8
9 2 6 8 7 7 1 0 2 7
怎么写代码实现上面的效果?
for (j = 0;j < 5,j++){
你的数组2[j][i] = 你的数组1[i][j];
}
}if (你的矩阵维数不一样){
吧你的数组维数设成大的那一个;
}
{
for(int i=0;i<myArray.length;i++)
{
for(int j=0;j<myArray.length;j++)
{
myArray[i][j]=(int)(Math.random()*10);
}
}
print(myArray);
for(int i=0;i<myArray.length;i++)
{
for(int j=i+1;j<myArray.length;j++)
{
int temp=myArray[i][j];
myArray[i][j]=myArray[j][i];
myArray[j][i]=temp;
}
}
print(myArray);
}
public static void print(int[][] myArray)
{
for(int i=0;i<myArray.length;i++)
{
for(int j=0;j<myArray.length;j++)
{
System.out.print(myArray[i][j]);
}
System.out.println();
}
}
结果:88233
30652
37322
56190
9060683359
80760
26316
35290
32206