Summing Up A 2D Array

前端 未结 3 776
醉话见心
醉话见心 2021-01-28 05:53

Given my current program, I would like it to calculate the sum of each column and each row once the user has entered all their values. My current code seems to be just doubling

3条回答
  •  一整个雨季
    2021-01-28 06:20

    Your code is ok, but at the end for summation of column you should change the rows instead of column. like this:

    System.out.println("\n");
    
        for( int column = 0; column < columns; column++)
        {
            for(int row = 0; row < rows; row++)
                {
                array2d[row][column] = array2d[row][column] + array2d[row][column];
                System.out.print(array2d[row][column] + " ");
                }
             System.out.println();
        }
    

提交回复
热议问题