java如何返回这样一个多维数组
这有点复杂:
int[][] generate(int[][] input)
创建一个与输入具有相同结构的新数组。
每行的内容都写在下一行。最后一行的内容位于第一行。如果一行的长度对于所有移动的数字来说都太短,则剩余的数字将添加到此行的每个元素上。如果行的长度对于所有移位的数字都太长,则剩余字段将用此行中数字的平均值填充
例如:输入:
int[][] test1 = { {1, 2, 3, -4, -9}, {-20, 13}, {30, 19, 12, -12} }
输出:
{ {30, 19, 12, -12, 12}, {-9, -8}, {-20, 13, -3, -3} }
如果您能给我一些建议,例如我的if语句应该是什么样子,我将非常感激
# 1 楼答案
下面是旋转方法的一个可能实现。我在注释中添加了对代码所做操作的解释:
输入:
输出为: