Lesson 8: int & arithmetic
So far we worked with text. Now whole numbers: the int type. You declare it like a string but with no quotes: int age = 20;. On an int you can do arithmetic: + add, - subtract, * multiply, / divide, and % remainder (modulo). Note the key difference: numbers add up (3 + 4 = 7), while strings stick ("
int is a box for a whole number (no fraction). You can do normal math on it. % gives what's left after dividing — like splitting candy and checking how many remain.
- int
- A type for a whole number, e.g. 0, 5, -12. No quotes, no fraction.
- operators + - * /
- Arithmetic signs: add, subtract, multiply, divide.
- modulo %
- Returns the remainder of a division. 7 % 3 is 1.
- number vs string
- 3 + 4 adds to 7; "3" + "4" sticks into 34.