Problem of the Day
Friday, January 16, 2026
Problem:
Consider the following definition.
int[][] arr = {{ 0, 1, 2, 3},
{ 4, 5, 6, 7},
{ 8, 9, 10, 11},
{12, 13, 14, 15}};What does the following code segment print?
int s = 0;
for (int i = 0; i < arr.length; i++)
{
s = s + arr[0][i];
s = s + arr[arr.length - 1][i];
}
System.out.println(s);
- The sum of the values in the first and last columns of the array
- The sum of the values in the first and last rows of the array
- The sum of the values in the diagonals of the array
- The sum of the four corner values in the array
The correct answer is b. The first summation statement, s = s + arr[0][i]; adds the values from row 0, while the second statement sums the values in the bottom row.