Skip to content

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++ || ++x
Augmented/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 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.

  1. Parenthesis () has the highest priority.
  2. Multiplication and division are 2nd highest order */
  3. Finally Addition and subtraction +-