AP CSA 2.5 Exercise 1: In Range, Out of Range

Unit 2: Selection and Iteration · Lesson 2.5 · Exercise 1

In Range, Out of Range

Compound Boolean Expressions. Write real Java, run it, and submit it to be graded against hidden test cases.

Why this one is worth doing

Every one of these is a single boolean expression printed directly, so there is nowhere for a stray if to hide the logic. If the expression is wrong the printed value says so immediately.

What to write

  1. Read three integers: low, high and value.
  2. Print whether value is inside the range, meaning it is at least low AND at most high.
  3. Print whether value is outside the range, using OR rather than negating the first answer.
  4. Print whether value equals low OR equals high.
  5. Print the negation of the first expression using the ! operator, which should always match the second line.

Your program reads

Three integers on separate lines: low, high, value.

Your program prints

Four lines, each true or false.

Worked examples

These are the cases you can see. There are more you cannot, and they use different values, so an answer that prints these numbers as constants will fail.

Example 1 input
1
10
5
Example 1 output
true
false
false
false
Example 2 input
1
10
10
Example 2 output
true
false
true
false

Your answer

Main.java

Input for the Run button

Run sends whatever is in the input box below. Submitting runs your program against every test case, including hidden ones with different input.


  

  

Stuck?

Hint 1

Java has no low <= value <= high. It has to be written as two comparisons joined with &&.

Hint 2

The opposite of "at least low and at most high" is "below low or above high". The and becomes an or, which is De Morgan and is 2.6.

Hint 3

Lines 2 and 4 must agree on every input. If they ever disagree, one of your two expressions is wrong.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]