Java Arena
Step 1 of 6

Booleans in conditions

A comparison like age >= 18 is an expression with a value, and that value is a boolean: true or false. It can be stored in a variable, printed, or used later as a condition:

int age = 20;
boolean adult = age >= 18;
System.out.println("Adult: " + adult);
if (adult) {
    System.out.println("Welcome in.");
}
Output
Adult: true
Welcome in.

if (adult) reads naturally: the condition is the variable itself, so there's no need to write if (adult == true).

A well-named boolean variable makes a condition easier to read, especially when the test is long or used more than once. Names like adult, isRaining or hasTicket work well: they read like yes-or-no questions.

Your task

Challenge 1 of 3

Fill in the blank, so canVote is true for an age of 18 or more. For the input 20 the program prints Can vote: true.

Challenge 2

Read whether the customer is a member (true or false) into a boolean. Use the variable itself as the condition: members get Discount applied, others Full price. For the input true the program prints:

Discount applied

Challenge 3

Read a temperature (an int) and whether it's raining (true or false). Store temperature > 20 in a boolean called warm. Then print Wear a T-shirt when it's warm and Wear a sweater otherwise, and add Take an umbrella when it's raining. For the input 24 and true the program prints:

Wear a T-shirt
Take an umbrella