Lesson 5.5 · Trace it
Trace: list index (Java)
Java code5 rows to fill4 marks
Complete the trace table for this Java code. prices[i] is the value at index i, and prices.length is the number of values. [4]
Line 1: int[] prices = {4, 9, 2, 7};Line 2: int i = 1;Line 3: int a = prices[i];Line 4: i = prices.length - 1;Line 5: int b = prices[i];Line 6: System.out.println(a + b);
Fill in one row each time a line changes i, a or b, or prints something. The table already has the right number of rows. In each row, write only what that line changes; you can leave the other cells empty or copy their values down. Write values the way Java shows them: 3 and 3.0 are different, and text goes in quotes. In the output column, write exactly what appears on screen, with no quotes around it.
| Row | i | a | b | output |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 |