Java Reference
In-Depth Information
3
Flow of Control
3.1 BRANCHING MECHANISM
100
if-else
Statements 100
Omitting the
else
101
Compound Statements 102
Nested Statements 104
Multiway
if-else
Statement 104
Example: State Income Tax 105
The
switch
Statement 107
The Conditional Operator
3.4 DEBUGGING
150
Loop Bugs 150
Tracing Variables 150
General Debugging Techniques 151
Example: Debugging an Input Validation Loop 152
Preventive Coding 156
Assertion Checks
★
157
3.5 RANDOM NUMBER GENERATION
★
159
★
112
The
Random
Object 160
The
Math.random()
Method 161
3.2 BOOLEAN EXPRESSIONS
113
Simple Boolean Expressions 113
Lexicographic and Alphabetical Order 116
Building Boolean Expressions 119
Evaluating Boolean Expressions 120
Short-Circuit and Complete Evaluation 124
Precedence and Associativity Rules 125
3.3 LOOPS
132
while
Statement and
do-while
Statement 132
Algorithms and Pseudocode
134
Example: Averaging a List of Scores 137
The
for
Statement 138
The Comma in
for
Statements 141
Nested Loops 145
The
break
and
continue
Statements
★
148
The
exit
Statement 149
Chapter Summary 162
Answers to Self-Test Exercises 162
Programming Projects 168