CHAPTER 3
DECISIONS
CHAPTER GOALS
To implement decisions using if statements
To compare integers, floating-point numbers, and strings
To write statements using the Boolean data type
To develop strategies for testing your programs
To validate user input
CHAPTER CONTENTS
Programming Tip 3.1: Brace Layout
Programming Tip 3.2: Always Use Braces
Common Error 3.1: A Semicolon After the if Condition
Special Topic 3.1: The Conditional Operator
Programming Tip 3.4: Avoid Duplication in Branches
3.2 COMPARING NUMBERS AND STRINGS
Common Error 3.2: Exact Comparison of Floating-Point Numbers
Common Error 3.3: Using == to Compare Strings
Special Topic 3.2: Lexicographic Ordering of Strings
How To 3.1: Implementing an if Statement
Worked Example 3.1: Extracting the Middle
Random Fact 3.1: The Denver Airport Luggage Handling System
Special Topic 3.3: The switch Statement
Programming Tip 3.5: Hand-Tracing
Common Error 3.4: The Dangling else Problem
Special Topic 3.4: Enumeration Types
Get Java For Everyone: Compatible with Java 5, 6, and 7, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.