Learn AP Comp Sci

☰

Problem of the Day

Thursday, November 26, 2026


Problem:

A program that identifies storms uses conditional statements to determine the category of a hurricane based on its windspeed. A snippet of that code is given here.

/*
* Given a wind speed in miles per hour, identify the hurricane category
*/
String mssg;
if (windSpeed < 74)
mssg = "Not a hurricane";
else if (windSpeed < 96)
mssg = "Category One Hurricane";
else if (windSpeed < 111)
mssg = "Category Two Hurricane";
else if (windSpeed < 130)
mssg = "Category Three Hurricane";
else if (windSpeed < 157)
mssg = "Category Four Hurricane";
else
mssg = "Category Five Hurricane";

For a hurricane with a windspeed of 120 miles-per-hour, how many boolean expressions will be evaluated before the correct value of mssg is assigned?

  1. 0
  2. 3
  3. 4
  4. 5

Show solution:

The correct answer is c. This series of conditionals attempting to identify which category to place something in is very common, so common that a special switch statement is available in some languages (including Java) to implement it.