所以,基本上我想用我的代码做的是让用户可以输入一个值,然后程序将添加任何值到数组中的所有值
//我的代码
{
//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/