A variable is a typed box; an operator is the action performed on what is inside. Together they do all the real work.
1 Typed boxes
int count, double price, boolean ok, String name — declare the type once and Java enforces it forever.
2 Arithmetic
+ - * / % compute numbers. Careful: 7 / 2 is 3 when both sides are ints — the fraction is dropped.
3 Compare and combine
== != < > <= >= produce booleans; && || ! combine or flip them.
4 Assign shortcuts
= stores a value; +=, -= and ++ update in place: total += 5 is total = total + 5.
Variables + operators = work
Typed boxes1int count, double price, boolean ok, String name — declare the type once and Java enforces it forever. Arithmetic2+ - * / % compute numbers. Careful: 7 / 2 is 3 when both sides are ints — the fraction is dropped. Compare and combine3== != < > <= >= produce booleans; && || ! combine or flip them. Assign shortcuts4= stores a value; +=, -= and ++ update in place: total += 5 is total = total + 5. 4 building blocks make up Variables + operators = work
Press play and watch arithmetic, remainder, division and logic compute one by one.
JVMThe JVM loads the OpsDemo class into memory.
Memory
no variables yet — press play
Console
output appears as the program runs…
This pass/fail check is the expression marks >= 40 && attend >= 75 drawn as a flowchart — both sides must say yes.
process decision input / output start / end Click an operator, then click what it does to lock the pair.
6 conceptsTap a card to expand ?&&drops into place
?||drops into place
?++drops into place
?==drops into place
Two classic traps in one program: integer division and operator precedence.
Your predicted output — one line per console line
Hint: When both sides of / are ints, Java throws away the fraction. And * runs before -.
01Operators compute: + - * / % for numbers, with % giving the remainder.
02int / int throws away the fraction — 7 / 2 is 3, not 3.5.
03Comparisons produce booleans: == != < > <= >=.
04&& needs both sides true; || needs at least one; ! flips a boolean.
05+=, -= and ++ are shortcuts for updating a variable in place.