CHAPTER 14 — Boolean Expressions

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to home page   hear noise   go to next page

revised: 10/01/98, 12/09/99, 01/20/00, 01/14/06, 06/04/06, 10/08/08

CHAPTER 14 — Boolean Expressions

The if statements of the previous chapters ask simple questions such as count<10. Often simple questions are not enough. This chapter discusses ways to ask more complicated questions.

Chapter Topics:

  • Relational Operators (review)
  • Logical Operators
  • AND Operator
  • How to check that a number is in range
  • Boolean Expressions
  • OR Operator
  • Comparison between AND and OR
  • NOT Operator

Questions involving boolean expressions have been prominent on past AP Computer Science Tests.

QUESTION 1:

You have decided to bake some cookies (much cheaper than buying them at the Mall).

An interesting cookie recipe calls for 4 cups of flour and 2 cups of sugar. You look in your pantry and find 3 cups of flour and 2 cups of sugar.

Can you bake cookies with what you have?