-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
The second code snippet from the Unary section does not illustrate the core difference between the pre and post increment operators well (++i vs i++):
https://dev.java/learn/language-basics/using-operators/#unary
Both
System.out.println(++i);
and
System.out.println(i++);
produce the same output so it might be confusing as to what is the actual difference.
I would suggest replacing it with something along the lines of
int i = 3;
i++;
// prints "i = 4"
System.out.println("i = " + i);
++i;
// prints "i = 5"
System.out.println("i = " + i);
int j = ++i;
// prints "i = 6"
System.out.println("i = " + i);
// prints "j = 6"
System.out.println("j = " + j);
int k = i++;
// prints "i = 7"
System.out.println("i = " + i);
// prints "k = 6"
System.out.println("k = " + k);
Metadata
Metadata
Assignees
Labels
No labels