These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

JAVA01/Variable Operators

Classnotes | JAVA01 | RecentChanges | Preferences

All these variables really wouldn't be very useful unless you could do things with them, and that's where operators come in.

There are many different operators that you can use on variables, and some have different functionality depending upon the type of variable it is acting upon.

Numerical Operators

The basic numerical operators are +, -, *, /, and %.

'+' is for addition

 a = b + 10;

'-' is for subtraction

 a = b - 10;

'*' is for multiplication

 a = b * 10;

'/' is for division

 a = b / 10;

'%' is for finding the remainder after a division

 a = b % 10;

Beyond these basic ones, there are the increment and decrement operators, '++' and '--'.

'++' increments a variable by one, such that

 b++;
is equivalent to
 b = b + 1;

Likewise

 b--;
is equivalent to
 b = b - 1;

Precedence

When you are using an expression with more than one operator, you need to know what order the computer will use as it works out the expression. Under Java, that order is:
  1. ++ and --
  2. *, /, and %
  3. + and -
  4. Comparison (==, etc.)
  5. The equal sign, =



Classnotes | JAVA01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited May 27, 2003 10:05 pm (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.