gpt4 book ai didi

java - 矩阵操作Java

转载 作者:行者123 更新时间:2023-11-30 02:58:34 26 4
gpt4 key购买 nike

假设我有下一个二维 int 数组:

  int [][] mat = {{1 1 1 1 1}, 
{0 0 0 0 0},
{3 3 3 3 3},
{0 0 0 0 0},
{2 2 2 2 2}};

我在这里的原因是因为我试图想出一种方法来按下一个顺序对行进行洗牌(而不丢失第一行数据):

   first row data -> second row 
second row data -> third row
third row data -> fourth row
fourth row data -> fifth row

对我所写内容的更详细的图形解释:

    original: 1 1 1 1 1      what i need: 1 1 1 1 1 
0 0 0 0 0 1 1 1 1 1 <- first row data on the second row
3 3 3 3 3 0 0 0 0 0 <- second row data on the third row
0 0 0 0 0 3 3 3 3 3 <- third row data on the fourth row
2 2 2 2 2 0 0 0 0 0 <- fourth row data on the fifth row

meaning that the 1st row always remains constant
and that the original fifth row always loses its content

任何关于我如何实现这样的事情的建议/提示将不胜感激!

最佳答案

从最后一行向后迭代到第二行。

对于每一行,将前一行的值分配给它。

关于java - 矩阵操作Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com