交换两个二维浮点数组

u4vypkhs  于 2021-06-27  发布在  Java
关注(0)|答案(2)|浏览(313)

我想交换两个二维浮点数数组。

float[][] bluePath ={ 
     {-.025f,-.303f},
     {-.025f,.05f},
     {-0.38f,-.215f}
}

float[][] greenPath ={ 
     {-.4f,-.23f},
     {-.55f,.03f},
     {-0.58f,-.55f}
}

交换后,我要跟踪result:-

float[][] bluePath ={ 
     {-.4f,-.23f},
     {-.55f,.03f},
     {-0.58f,-.55f}
}

float[][] greenPath ={ 
     {-.025f,-.303f},
     {-.025f,.05f},
     {-0.38f,-.215f}

}

请帮我解决这个问题。

zvokhttg

zvokhttg1#

使用临时变量并逐字节复制。

for ( int i = 0; i < 3; i++ )
{
  for ( int j = 0; j < 2, j++ )
  {
    float fHelp = redPath[i][j];
    redPath[i][j] = greenPath[i][j];
    greenPath[i][j] = fHelp;
  }
}
sbdsn5lh

sbdsn5lh2#

您可以使用以下代码:

float temp;
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 2; j++) {
        temp = bluePath[i][j];
        bluePath[i][j] = greenPath[i][j];
        greenPath[i][j] = temp;
    }
}

相关问题