Task 3 of 8 · 0 solved · 8 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

1.2 Variables — reassignment

Lesson

Reassignment overwrites

Assigning a new value replaces the old one — it does not keep both. And score = score + 5 means: take the current value, add 5, and store the result back.


Worked example

int score = 10;
System.out.println(score);  // 10
score = 25;
System.out.println(score);  // 25
score = score + 5;
System.out.println(score);  // 30

▶ Try it: run this, then change something and run it again.



What does this print?

int n = 4;
n = 9;
System.out.println(n);

What does this print?

int a = 3;
int b = 5;
a = b;
b = a;
System.out.println(a + " " + b);

Type exactly what this prints:

int x = 5;
x = x + 3;
System.out.println(x);

Arrange the lines so the program prints 10.


True or false?