KwickCards Java
Dry run with a trace table

ICSE · DRY RUN
Dry run with a trace table
| Step | i | sum |
|---|---|---|
| start | 1 | 0 |
| pass 1 | 2 | 1 |
| pass 2 | 3 | 3 |
| pass 3 | 4 | 6 |
One column per variable, one row per step
Output questions become easy once you dry run them the right way.
Guessing the output from memory leads to mistakes. A dry-run table keeps every change visible, especially for loops, increments and nested conditions.
Notice whether the code uses print() or println(), because that decides whether output appears on the same line.
Practise this method on every output question for two weeks and you will see the difference.
The table traces: int sum = 0; for (int i = 1; i <= 3; i++) sum += i; The loop stops when i becomes 4, so sum is 6.
More on this: free Java lessons
More Java cards
ICSE Java
ISC CS
Java Output
Index the letters of BlueJ
Math methods: watch the return type
Trace a for loop that adds 3Written by Kajal Mehta (Kajal Ma'am), MCA, teaching computer subjects since 2004. All KwickCards · KwickAcademy

