Practice Exercise: Basic Arithmetic Statements
Arithmetic Operators: | Assignment Operators:
() overrides order | = a single equal sign is the simple assignment
Increment ++ | operator; it assigns the result from evaluating
Decrement -- | the expression on the right side to the variable
Negative - | left of the = sign; Compound operators follow:
Multiplication * | *= "times equals" assigns product of both to left
Division / | /= "divide equals" assigns quotient to left side
Addition + | += "plus equals" assigns sum
Subtraction - | -= "minus equals" assigns difference
Modulus % | %= "modulus equals" assigns remainder
1. Increment(add): show three ways to increment an integer variable named count
by 1.
2. Addition: Assign to a variable named netPrice the sum of price plus tax.
3. Subtraction: Show two ways to find balance as the difference of balance and
withdrawalAmount.
4. Multiplication: Assign to a variable named interest the value of balance
multiplied by rate.
5. Division: Compute milesPerGallon by dividing miles by gallons.
6. Multiplication and Division: Write statements to reduce the value referenced
by the variable debt by half--one with a multiply operation and the other
with a divide.
7. Modulus (remainder): Find the number of 49 cent stamps that may be bought
with one dollar (100 cents), and the cents to be returned as change.