The ++ and -- operators are convenience operators that many programmers like because they save some
typing. The following two statements have the same effect:
m = m + 1;
m++;
In either case, the value of m will increase by 1. The -- operator works similarly, except that the value of
the variable will decrease by 1.
The rest of the operators in our list are logical operators. We use logical operators to test the truth of conditions
important to our programs. For example, if our program were going to find all the houses in a neighborhood
whose assessed values were greater than $200,000, our program might have a statement like this in it:
if ( assessedValue > 200000 ) {
70 PROGRAMMING IN JAVA [CHAP. 5
Operator Function
= assignment
+ add
- subtract
* multiply
/ divide
++ increment by 1
-- decrement by 1
&& logical AND
|| logical OR
== equal (notice that there are 2 equal signs)
!= not equal
> greater than
< less than
>= greater than or equal
<= less than or equal
We will discuss the use of if statements in the section on Java control structures, so for now simply
observe that the ???>??? operator allows one to test the truth of the condition that assessed value is greater than
$200,000.
Pages:
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197