java - 无法弄清楚如何增加二维数组

标签 java arrays multidimensional-array increment

所以,基本上我想用我的代码做的是让用户可以输入一个值,然后程序将添加任何值到数组中的所有值

//我的代码

{
    //creates array called table
    int[][] table = new int [10][10];

    //load the table with values
    for (int row=0; row < table.length; row++)
        for (int col=0; col < table[row].length; col++)
            table[row][col] = row * 10 + col;

    //Print the table
    for (int row=0; row < table.length; row++)
    {
        for (int col=0; col < table[row].length; col++)
            System.out.print (table[row][col] + "\t");
        System.out.println();

int incr;
Scanner scan = new Scanner(System.in);

System.out.println("");
System.out.println("What do you want to increment by?");
incr = scan.nextInt();


for (int row=0; row < table.length; row++)
    {
        for (int col=0; col < table[row].length; col++)
            System.out.print (table[row][col] + "\t");

       System.out.println();



    }
}

这是我到目前为止的代码,我不知道从这里去哪里。如果有人能帮我解决这个问题,那就太好了。

最佳答案

在循环内添加以下代码行: 表[行][列] += incr;

关于java - 无法弄清楚如何增加二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36705584/

相关文章:

java - 如何从 rest api 序列化枚举列表

java - 按 ID 对 JSON 数组排序

arrays - 使用 VBA 中的默认值数组使用大纲填充 Excel WBS

java - 嵌套循环,如何制作日历

java - 如何在 Java 中打断长行

c++ - 数组大小 'exceeded' ,但数组很小

javascript - 使用 Lodash 从集合中删除 "column"的最佳方法?

ios - 来自多个循环的对象数组

python - Numpy 重新排序,以便将当前行中的每第 n 行追加到该行

python - Python多维数组索引说明