๐ WAYPOINT LESSON
Overflow and mixed types
โญ beginnerโณ 10 min read๐ Lesson 7 of 256
int range, silent overflow, String concatenation order, char arithmetic.
An int has 32 bits: values from โ2ยณยน (โ2147483648) to 2ยณยน โ 1 (2147483647).
Overflow wraps around silently:
int big = 2147483647;
big = big + 1;
System.out.println(big); // -2147483648 โ wrapped!
Two int-only operators the exam loves:
+on ints with Strings:"score: " + 90โ"score: 90"(concatenation). Left to right:1 + 2 + "x"โ"3x", but"x" + 1 + 2โ"x12".%(remainder) works on negatives with the sign of the dividend:-7 % 3is-1.
char participates in arithmetic through its Unicode value:
char c = 'A'; // 65
char next = (char) (c + 1); // 'B'
Casting an int that is out of char's range produces a different
character โ another silent wrap.