The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.2.

Click here to see other solutions to Introduction to Java Programming.

2 Comments

  1. The question did not specify how many decimal places the answer should be. But if you want yours to be like the sample run used in the textbook, you only need to change the format of the System.out.printf statement like this
    System.out.printf ("%s%.4f%s%.1f%s", "The Area is ", area, "nThe Volume is ", volume, "n");

  2. part of this exercise is to use type casting to truncate the area's decimal places so the answer won't be as long. The area is shown with only 4 decimal numbers and the volume shows only one. Would you happen to know how to add that to the computation?

Write A Comment