Numbers & Math
7 min · Java
Do math with int variables and the basic operators.
Java · Numbers & Math0/5 cleared
Enemy 1 of 5
Whole numbers use the int type (short for "integer"). The basic arithmetic operators are + (add), - (subtract), * (multiply), and / (divide), and Java follows the same order of operations you'd expect from math class: multiplication and division happen before addition and subtraction, unless parentheses say otherwise.
Store the parts in clearly-named int variables, then combine them inside println. Because both price and quantity are declared as int, Java guarantees the multiplication is safe, whole-number arithmetic — no risk of one of them secretly being text.
You
Syntax Skeleton
Loading editor...
Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: 15