Arithmetic Expressions
An expression is a piece of code that produces a value, Java has the same arithmetic operators we have in math.
Addition = +Subtraction = -Division = /Multiplication = *Modulus = %Increment = x++ || ++xAugmented/compounded Assignment Operators = += -= *= /=
In Java you must explicitly state the type for operands and return to the intended return format. As an example if you want a floating return of division you would need to apply:
float result = (double)10 / (double)3;
Prefix/Suffix Operands
Section titled “Prefix/Suffix Operands”Prefix
A value with a prefix operand ++X
will first increment on itself prior to assigning it to the expression.
Suffix
A value with a suffix operand x++
will first look to the expression prior to incrementing on itself.
Order of Operations
Section titled “Order of Operations”- Parenthesis
()
has the highest priority. - Multiplication and division are 2nd highest order
*/
- Finally Addition and subtraction
+-