这是我到目前为止的代码:
public static int mode(int[][] arr) {
ArrayList<Integer> list = new ArrayList<Integer>();
int temp = 0;
for(int i = 0; i < arr.length; i ++) {
for(int s = 0; s < arr.length; s ++) {
temp = arr[i][s];
我似乎在这一点上停留在如何将 [i][s]
放入一维数组中。当我执行 print(temp)
时,我的二维数组的所有元素一次按顺序打印一个,但无法弄清楚如何将它们放入一维数组中。我是新手:(
如何将二维数组转换为一维数组?
我目前使用的二维数组是 3x3。如果该背景很重要,我试图找到二维数组中所有整数的数学模式。
原文由 Kristopher 发布,翻译遵循 CC BY-SA 4.0 许可协议
你几乎做对了。只是一个微小的变化: