Java Reference
In-Depth Information
Chapter 4
Conditional Execution
Introduction
4.1 if/else Statements
Relational Operators
In the last few chapters, you've seen how to solve complex programming
problems using for loops to repeat certain tasks many times. You've also
seen how to introduce some flexibility into your programs by using class
constants and how to read values input by the user with a Scanner
object. Now we are going to explore a much more powerful technique
for writing code that can adapt to different situations.
Nested if/else Statements
Object Equality
Factoring if/else Statements
Testing Multiple Conditions
4.2 Cumulative Algorithms
Cumulative Sum
Min/Max Loops
Cumulative Sum with if
In this chapter, we'll look at conditional execution in the form of a control
structure known as the if/else statement. With if/else statements,
you can instruct the computer to execute different lines of code depend-
ing on whether certain conditions are true. The if/else statement, like
the for loop, is so powerful that you will wonder how you managed to
write programs without it.
Roundoff Errors
4.3 Text Processing
The char Type
char versus int
Cumulative Text Algorithms
System.out.printf
4.4 Methods with Conditional
Execution
This chapter will also expand your understanding of common program-
ming situations. It includes an exploration of loop techniques that we
haven't yet examined and includes a discussion of text-processing issues.
Adding conditional execution to your repertoire will also require us to
revisit methods, parameters, and return values so that you can better
understand some of the fine points.The chapter concludes with several
rules of thumb that help us to design better procedural programs.
Preconditions and
Postconditions
Throwing Exceptions
Revisiting Return Values
Reasoning about Paths
4.5 Case Study: Body Mass
Index
One-Person Unstructured
Solution
Two-Person Unstructured
Solution
Two-Person Structured Solution
Procedural Design Heuristics
226
 
Search WWH ::




Custom Search