Java Arena
Step 6 of 6

Tracing values

= copies a value into a variable, once. After a = b;, the variable a holds the same number as b, but the two aren't linked: changing b later doesn't change a.

int b = 5;
int a = b;
b = 8;
System.out.println(a);
System.out.println(b);
Output
5
8

When a program gets confusing, trace it by hand: go through it line by line and write down what each variable holds after each line.

After line a b
int b = 5; 5
int a = b; 5 5
b = 8; 5 8

Tracing is how programmers check their own thinking, and it's a skill worth practicing on paper, without running anything.

Your task

Challenge 1 of 3

What does this program print? Trace it and type each line.

Challenge 2

And this one? Watch the change to b after the copy.

Challenge 3

Three values this time. Trace carefully: the order of the lines matters.