Trace the following code and show the exact output.
1 public class ModifyArray2 {3 public static void main(String[] args)4 {5 int sum = 0;6 int[] list = new int[3];78 for (int i=0; i<3; i++)9 {10 list[i] = i + 100;11 }12 modify(list, sum);13 for (int i=0; i<3; i++)14 {15 System.out.print(list[i] + " ");16 }17 System.out.println("\nsum = " + sum);18 }1920 public static void modify(int[] list, int sum)21 {22 int temp = list[0];2324 list[0] = list[list.length - 1];25 list[list.length - 1] = temp;26 for (int i=0; i<3; i++)27 {28 sum += list[i];29 }30 }31 } // end ModifyArrayUse the following trace header:
| ModifyArray |
| ||||||||||
| main | modify | arr1 |
| ||||||||
line# | i | sum | list | (list) | (sum) | temp | i | length | 0 | 1 | 2 | output |
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.