Skip to content
ExamSpine

Lesson 3.8 · Trace it

Trace: step loop

Java code11 rows to fill3 marks

Complete the trace table for this Java code. Then answer the question below the table. [3]

Line 1: int i = 10;
Line 2: int steps = 0;
Line 3: while (i > 0) {
Line 4, indented 1 level: i = i - 3;
Line 5, indented 1 level: steps = steps + 1;
Line 6: }
Line 7: System.out.println(i);

Fill in one row each time a line changes i or steps, 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.

Rowistepsoutput
1
2
3
4
5
6
7
8
9
10
11