Problem

(Diameter, Circumference and Area of a Circle) Here's a peek ahead. In this chapter, y...

(Diameter, Circumference and Area of a Circle) Here's a peek ahead. In this chapter, you learned about integers and the type int. Java can also represent floating-point numbers that contain decimal points, such as 3.14159. 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. 4. [Note: You may also use the predefined con­stant Math.PI for the value of π This constant is more precise than the value 3.14159. Class Math is defined in package java.lang. Classes in that package are imported automatically, so you do not need to import class Math to use it.] Use the following formulas (r is the radius):

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.pri ntf statement. The values produced by the circum­ference and area calculations are floating-point numbers. Such values can be output with the for­mat specifier %f in a System.out.printf statement. You'll learn more about floating-point numbers in Chapter 3.

Fig. 4 | Addition program that inputs two numbers then displays their sum.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT