Chapter 4

Making Choices

In This Chapter

arrow Boolean expressions for fun and profit (or is it for fun or profit?)

arrow Your basic, run-of-the-mill if statement

arrow else clauses and else-if statements

arrow Nested if statements

arrow Logical operators

arrow The weird ?: operator

arrow The proper way to do string comparisons

So far in this book, all the programs have run straight through from start to finish without making any decisions along the way. In this chapter, you discover two Java statements that let you create some variety in your programs. The if statement lets you execute a statement or a block of statements only if some conditional test turns out to be true. And the switch statement lets you execute one of several blocks of statements depending on the value of an integer variable.

The if statement relies heavily ...

Get Java All-in-One For Dummies, 4th 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.