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
Welcome to the world of Java. First of let's dissect your "doubling the array" code.
array2d[row][column] = array2d[row][column] + array2d[row][column];
This line of code is the issue. The loops that you have applied tend to update the values of each of the elements in the matrix. For e.g. Suppose
array2d[1][2]=2
Hence the code mentioned above does this
array2d[1][2]= array2d[1][2]+array2d[1][2];
which essentially doubles the value of the array.
You should try something like this:
//To print the values of rows
for(int i=0;i
The below code will help you calculate the value of columns.
//To print values of columns
for(int i=0;i
Try making the code for the diagonal.It's pretty straightforward.
HINT : Main diagonals have row and column number to be the same.
P.S. - Add scan.close() to your code. Always close such connections to prevent resource leaks.