Boolean Expressions

This chapter introduces relational and logical operators. It also discusses the use of these operators to write Boolean expressions.

1. Boolean Expressions

The if statements of the previous chapters asked simple true/false questions (boolean expressions) such as count<10. Often simple boolean expressions are not enough. This chapter discusses more complicated boolean expressions.

Boolean expressions have been prominent on past AP Computer Science tests.

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

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?


Source: Bradley Kjell, http://programmedlessons.org/Java9/chap18/ch18_01.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 License.