Page 19
How to Perform Simple Algebra in Java
Topics
1. Arithmetic Operators
2. Unary and Binary Assignment Operators
3. Compiling Sourcecode and Running Bytecode
1. Assignment and Arithmetic Operators
i. Usual Assignment Operator
Let's first review the usual assignment operator "
=
"
int a = 3;
a = a+5;
The old value of 3, is replaced by 8. It is an
integer
type variable.
ii. Special Assignment Operators: "
+=
"
These special assignment operators are mostly just convenient
shorthands. They are used so frequently by master programmers
that you need to learn them to be able to understand, edit or
improve existing programs.
Q: What are the resulting values for a, b and c?
int a, b, c;
a = 3;
b = 4;
c = 5;
a += 5;
b += c;
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentPage 39
iii. Other Binary Assignment Operators
+=
=
*=
/=
%=
In all cases the variabsles on the left and right are
combined and the result is stored in the left variable –
replacing the previous value. Recall % denotes the
remainder operator. For example: 7%4 returns 3.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '07
 RobinCarr
 Special assignment, relational operator, assignment operators, Binary Assignment Operators, usual assignment operator

Click to edit the document details