222k views
0 votes
What is the printout of the following program?

public class Test { public static void main(String[] args) { int[][] values = {3, 4, 5, 1}, {33, 6, 1, 2}; for (int row = 0; row < values.length; row++) { System.out.print(m(values[row]) + " "); } } public static int m(int[] list) { int v = list[0]; for (int i = 1; i < list.length; i++) if (v < list[i]) v = list[i]; return v; } }

User Micapam
by
5.4k points

1 Answer

1 vote

Answer:

5 33

Step-by-step explanation:

The above-written JAVA code will print 5 33.

We have a 2-D array values that is initialized.Then we are iterating for the number of rows times that is 2 and both the times we are calling a function m and printing the value returned by it.

In the m function each row is passed as an 1-D array of the 2-D array.The first value of 1-D array is stored in the integer variable v.Then the array is iterated using a for loop and changing the variable v if there is any value greater than v in the array first time it is 5 and the second time it is 33 basically the function is finding the maximum form the array.

User Atiretoo
by
6.1k points