Chapter 7. Using Conditional Tests to Make Decisions

<feature><title></title>

WHAT YOU’LL LEARN IN THIS HOUR:

  • Using the if statement for basic conditional tests

  • Testing whether one value is greater than or less than another

  • Testing whether two values are equal or unequal

  • Using else statements as the opposite of if statements

  • Chaining several conditional tests together

  • Using the switch statement for complicated conditional tests

  • Creating complicated tests with the ternary operator

</feature>

When you write a computer program, you provide the computer with a list of instructions called statements, and these instructions are followed to the letter. You can tell the computer to work out some unpleasant mathematical formulas, and it works them out. Tell it ...

Get Sams Teach Yourself Java™ in 24 Hours, Fifth 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.