Java Reference
In-Depth Information
repeat statements a specified number of times. A loop can
contain another loop, called a nested loop.
An algorithm can be easier to write if you first write an
English description of it. Such a description is also called
pseudocode.
A variable exists from the line where it is declared to the
right curly brace that encloses it. This range, also called the
scope of the variable, constitutes the part of the program
where the variable can legally be used. A variable declared
inside a method or loop is called a local variable. A local
variable can only be used inside its method or loop.
Important constant values written into a program should be
declared as class constants, both to explain their names and
values and to make it easier to change their values later.
Self-Check Problems
Section 2.1: Basic Data Concepts
1. Which of the following are legal int literals?
22
1.5
-1
2.3
10.0
5.
-6875309
'7'
2. Trace the evaluation of the following expressions, and give their resulting values:
a. 2 + 3 * 4 - 6
b. 14 / 7 * 2 + 30 / 5 + 1
c. (12 + 3) / 4 * 2
d. (238 % 10 + 3) % 7
e. (18 - 7) * (43 % 10)
f. 2 + 19 % 5 - (11 * (5 / 2))
g. 813 % 100 / 3 + 2.4
h. 26 % 10 % 4 * 3
i. 22 + 4 * 2
j. 23 % 8 % 3
k. 12 - 2 - 3
l. 6/2 + 7/3
m. 6 * 7 % 4
n. 3 * 4 + 2 * 3
o. 177 % 100 % 10 / 2
p. 89 % (5 + 5) % 5
q. 392 / 10 % 10 / 2
r. 8 * 2 - 7 / 4
s. 37 % 20 % 3 * 4
t. 17 % 10 / 4
 
 
Search WWH ::




Custom Search