158k views
4 votes
Show the printout of the following code. public class Test { public static void main(String[] args) { double[][] m = {{1, 2, 3}, {1.5, 2.5, 3.5}, {0.1, 0.1, 0.1}}; System.out.println(sum(m)); } public static double sum(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }

1 Answer

2 votes

Answer:

The answer to the given question is "3.6".

Explanation:

The printout description of the given java program can be given as:

In this program, the printout of the following code is 3.6. because in this program we define an array and assign elements on the array and calculate the sum of the elements but in the loop, we calculate the sum of rows value that is i [1][1]= 1.0, i [2][2]=2.5 and i [3][3]=0.1 then we calculate sum that is equal to 3.6.

That's why the answer to this question is "3.6".

User Rizon
by
5.1k points