The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.28.

Question: Write an application that inputs from the user the radius of a circle as an integer and prints the circle’s diameter, circumference and area using the floating-point value 3.14159 for π. Use the techniques shown in Fig. 2.7. [Note: You may also use the predefined constant Math.PI for the value of π. Use the following formulas (r is the radius):

diameter = 2r
circumference = 2πr
area = πr2

Do not store the results of each calculation in a variable. Rather, specify each calculation as the value that will be output in a System.out.printf statement. The values produced by the circumference and area calculations are floating-point numbers. Such values can be output with the format specifier %f in a System.out.printf statement.

Click here to see other answers to Java How to Program.

Write A Comment