System.out.print(matrix [i] [j] + " ");
int sum = 0;
for (int row=0; row < matrix.length; row++)
for (int col=0; col < matrix[row].length; col++)
sum = sum + matrix[row];
I keep getting the wrong answers when the rows are added.
The sum for row 0 is 4 (should be 10)
Thank you for the opportunity to help you with your question!
The answer is :
for (int row=0; row < 4; row++)
for (int col=0; col < 4; col++)
sum = sum + matrix[row][col]; // or you can use sum += matrix[row][col];
ask if you don't understand
Content will be erased after question is completed.
Enter the email address associated with your account, and we will email you a link to reset your password.
Forgot your password?