Java Reference
In-Depth Information
is equivalent to
x+ = (y - = (-( ~ 4)));
or, in long hand,
int a =~4;
a = -a;
y = y-a;
x = x+y;
2.8.5 More operator tricks
Finally, here are some additional notes about operators. As indicated in the last
example above, assignment operations can be chained:
x = y = z = 4;
with the evaluations proceeding from right to left.
Assignments can be combined into other operations, to compact the code,
as in
if ((x = 5) == b) y = 10;
which first sets x to 5, then returns that value for the test of b . This technique
should generally be avoided as it makes the code difficult to read.
2.9 Statements
A statement in Java, like most computer languages, corresponds to a complete
sentence in a spoken language. It performs some complete action or set of actions.
It can encompass multiple operators and operands, as well as multiple sub-
statements. A single statement ends with a semi-colon and a set of multiple
sub-statements is enclosed in braces.
The statement,
x = 5.3 *(4.1 / Math.cos (0.2*y));
consists of several expression - multiplication, division, and an invocation of a
method - but is still considered a single statement.
Agroup of statements enclosed in braces - called a code block or compound
statement - acts as a single statement. For example, a simple if test looks like
this
if (test) statement;
Search WWH ::




Custom Search