9. Assignment Statements « Contents »   

variableName = expression

Example
pay = rate * hours

The variable is assigned the value of the expression. Note the previous value of the variable is destroyed. The expression can be a single variable, a single constant or involve variables, constants and the arithmetic operators list below.

N.B. The destination variable is on the left of the = sign.

Arithmetic Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus

An expression can also be a call to a method e.g.
num = Console.readInt();

   « Back Back to Top Next »