Java Reference
In-Depth Information
Section 4.13 Increment and Decrement Operators
• The unary increment operator, ++ , and the unary decrement operator, -- , add 1 to or subtract 1
from the value of a numeric variable (p. 131).
• An increment or decrement operator that's prefixed (p. 131) to a variable is the prefix increment
or prefix decrement operator, respectively. An increment or decrement operator that's postfixed
(p. 131) to a variable is the postfix increment or postfix decrement operator, respectively.
• Using the prefix increment or decrement operator to add or subtract 1 is known as preincrement-
ing or predecrementing, respectively.
• Preincrementing or predecrementing a variable causes the variable to be incremented or decre-
mented by 1; then the new value of the variable is used in the expression in which it appears.
• Using the postfix increment or decrement operator to add or subtract 1 is known as postincre-
menting or postdecrementing, respectively.
• Postincrementing or postdecrementing the variable causes its value to be used in the expression
in which it appears; then the variable's value is incremented or decremented by 1.
• When incrementing or decrementing a variable in a statement by itself, the prefix and postfix
increment have the same effect, and the prefix and postfix decrement have the same effect.
Section 4.14 Primitive Types
• Java requires all variables to have a type. Thus, Java is referred to as a strongly typed language
(p. 134).
• Java uses Unicode characters and IEEE 754 floating-point numbers.
Self-Review Exercises
4.1
Fill in the blanks in each of the following statements:
a)
All programs can be written in terms of three types of control structures:
,
and .
b) The statement is used to execute one action when a condition is true and
another when that condition is false.
c) Repeating a set of instructions a specific number of times is called repetition.
d) When it's not known in advance how many times a set of statements will be repeated,
a(n)
value can be used to terminate the repetition.
e) The
structure is built into Java; by default, statements execute in the order
they appear.
f)
Instance variables of types char , byte , short , int , long , float and double are all given
the value
by default.
g)
Java is a(n)
language; it requires all variables to have a type.
h)
If the increment operator is to a variable, first the variable is incremented by
1, then its new value is used in the expression.
4.2
State whether each of the following is true or false . If false , explain why.
a)
An algorithm is a procedure for solving a problem in terms of the actions to execute and
the order in which they execute.
b)
A set of statements contained within a pair of parentheses is called a block.
c)
A selection statement specifies that an action is to be repeated while some condition re-
mains true.
d)
A nested control statement appears in the body of another control statement.
e)
Java provides the arithmetic compound assignment operators += , -= , *= , /= and %= for
abbreviating assignment expressions.
 
Search WWH ::




Custom Search