Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Consider the following JAVA program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to

Consider the following JAVA program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder, and outputs the volume and surface area of the cylinder. Also modify the relevant output statements to format the output to two decimal places.

public class Ch3_PrExercise2

{

public static void main(String[] args)

{

} import }

System.out.print("Enter the height of the cylinder: ");

radius = console.nextDouble();

System.out.println();

static Scanner console = new Scanner(System.in);

System.out.println("Volume of the cylinder = " + PI * Math.pow(radius, 2.0) * height);

System.out.print("Enter the radius of the base of the " + " cylinder: ");

height = console.nextDouble();

System.out.println();

double height;

double radius;

System.out.println("Surface area: " + (2 * PI * Math.pow(radius, 2.0)) + (2 * PI * radius * height));

static final double PI = 3.14159; java.util.*;

}

}

import java.util.*;

This is what I have come up with so far...please help.

The last two highlighted two areas I can't get pass through

import static java.time.Clock.system; import java.util.*; public class Lab2_Exercise2 { //declare the static fields out of the main method static Scanner console = new Scanner(System.in); static final double PI=3.14159;

//start main method public static void main(String []args) { //declare the variables first double height, radius; //prompt user to enter height of the cylinder System.out.print ("Enter the height of the cylinder:"); //get and store the height height = console.nextDouble(); System.out.println(); //prompt user to enter radius System.out.print ("Enter the radius of the base of the cylinder:"); //get and store the radiu radius = console.nextDouble (); System.out.println (); /*calculate volume of the cylinder and display the result up to two decimal places*/ System.out.println ("Volume of the cylinder ="+PI * Math.pow (radius, 2.0 * height); /*calculate surface area of the cylinder and display the result up to two decimal places*/ System.out.printin ("Surface area:" +(2* PI* Math.pow(radius, 2.0)) +( 2*PI * radius * height)); } // end of main method } //end of exercise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions