Java Arena
Step 1 of 6

if

So far every line of a program ran every time. An if statement runs a block of code only when a condition is true:

int temperature = 31;
if (temperature > 30) {
    System.out.println("Hot day: drink water.");
}
System.out.println("Temperature: " + temperature);
Output
Hot day: drink water.
Temperature: 31
  • The condition goes in parentheses after if. Here it's temperature > 30, which is either true or false.
  • The block in braces { } runs only when the condition is true. With temperature = 25, the program would print only the second line.
  • The line after the block runs either way.

No semicolon after the condition

A semicolon right after if (...) ends the if there, with nothing in it. The block below it then runs every time, and Java doesn't warn about it:

int speed = 30;
if (speed > 50); {
    System.out.println("Too fast!");
}
Output
Too fast!

Only 30, and yet "Too fast!". When an if seems to be ignored, check for this semicolon first.

Your task

Challenge 1 of 3

Fill in the condition, so the program prints Too heavy for the cabin. only when the bag weighs over 8 kilograms. Every run ends with Have a good flight.

Challenge 2

Read a temperature and print Hot day: drink water. when it's over 30. Then always print the temperature. For the input 31 the program prints:

Hot day: drink water.
Temperature: 31

Challenge 3

Two separate checks on one number. Print Big number when it's over 100 and Negative number when it's below 0, then always Done. For the input 250 the program prints:

Big number
Done