Learn AP Comp Sci

☰

Problem of the Day

Thursday, October 1, 2026


Problem:

The surface area of a cone is given by the formula



where r refers to the radius of the base and h refers to the vertical height of the cone, as shown.

Which Java instruction will correctly calculate the surface area of a cone?

  1. double cone_area = Math.PI * r * r + Math.sqrt(h * h + r * r);
  2. double cone_area = Math.PI * r * r + Math.sqrt(h * h) + Math.sqrt(r * r);
  3. double cone_area = Math.PI * r * (r + Math.sqrt(h * h + r * r));
  4. double cone_area = Math.PI * r * (r + Math.sqrt(h * h) + Math.sqrt(r * r));

Show solution:

The correct answer is c. Using parentheses and the order of operations is important for having a program correctly determine the result of a mathematical calculation. Here, we could have also used Math.pow(h,2) and Math.pow(r,2) to calculate the squares of those values.