Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* Write an application that inputs from the user the radius of a circle as an integer and * prints the circle's diameter, circumference

  

* 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 n. * Use the techniques shown in Fig. 2.7. * [Note: You may also use the predefined constant Math.PI for the value of A. * 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): * diameter = 2r * circumference = 2nr area = nr 2 * 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. Note that 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. */ public class Exercise0222 // main method begins execution of Java application public static void main(String[] args) { // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); int r; // user input for circle's radius System.out.print("Enter the radius of the circle: "); // prompt r = input.nextInt(); // read radius input !3! System.out.printf("Diameter of the circle is Xd ", (2 * r)); // calculates the diameter System.out.printf("Circumference of the circle is %.2f ", (2* (Math.PI) * r)); // calculates the circumference System.out.printf("Area of the circle is %.2f ", ((Math.PI) (r * r))); // calculates the area } // end method main } // end class Exercise0222 /* Output: * Enter the radius of the circle: 6 * Diameter of the circle is 12 * Circumference of the circle is 37.70 * Area of the circle is 113.10 */

Step by Step Solution

3.42 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

For designing an application that inputs from the us... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modeling the Dynamics of Life Calculus and Probability for Life Scientists

Authors: Frederick R. Adler

3rd edition

840064187, 978-1285225975, 128522597X, 978-0840064189

More Books

Students also viewed these Operating System questions

Question

What, if any, financial support do they provide their students?

Answered: 1 week ago

Question

Copy and complete the statement. 3800 m ? km =

Answered: 1 week ago