Description Operators Associativity: Parentheses
Description Operators Associativity: Parentheses
Basic operators:
Description
Operators
Associativity
Parentheses
()
L to R
multiplication, division, modulus
* / %
L to R as they appear
addition, subtraction
+ -
L to R as they appear
What is integer division?
An int is a whole number. When you divide with integers, the remainder is truncated (done away
with). You are left with just the whole number.
Example:
7/2 = 3
5/2 = 2
14 / 3 = 4
Example: 7/2 = 3
15/4 = 3
What is modulus?
remainder.
7.0/2 =
3.5
7/2.0 = 3.5
15.0/4 = 3.75
Modulus is the remainder operator. You will divide and then the answer is the
7/2 = 3
7%2 = 1
answer is 1
answer is 1
2 7
7
-6____
1
Open Dr. Java. At the bottom left, click on the tab that says Interactions Pane.
Type each of these into the interactions pane and record the result.
32/ 3
32.0 / 3
14/5
14.0 / 5
18 / 4
18.0 / 4
What did you observe when dividing with a decimal (float value)
Modulus Operator:
Type these into the interactions pane and record the result.
32 % 3
14 % 5
18 % 4
18 % 4
12 % 5
Description
Operators
Associativity
Parentheses
()
L to R
multiplication, division, modulus
* / %
Then type them into the interactions pane to check your work.
Example:
3*6-4/2
3* 6 = 18
4/2 = 2
18-2 = 16
6/3*2
((4+9) * 2+3) * 2) + 1
2 + 3 * 2 + 15 / 5
12 + 3 % 4 + 1