24.2k views
4 votes
Rearrange the statements in the following order so that the program prompts the user to input: a. The height of the base of a cylinder b. The radius of the base of a cylinder The program then outputs (in order): a. The volume of the cylinder. b. The surface area of the cylinder c. Format the output to two decimal places.

1 Answer

0 votes

Answer:

import java.util.Scanner;

public class num5 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter base heigth of the cylinder");

double heigth = in.nextDouble();

System.out.println("Enter radius of the cylinder");

double radius = in.nextDouble();

// vol = pi*r2*h area = 2π r h + 2π r².

double volCylinder = Math.PI*(radius*radius)*heigth;

double surfaceAreaCylinder = (2*Math.PI*radius*heigth)+

(2*Math.PI*(radius*radius));

// Outputs

System.out.printf("The Vol of the cylinder %.2f \\",volCylinder);

System.out.printf("The surface Area %.2f \\", surfaceAreaCylinder);

}

}

Step-by-step explanation:

The program is written in Java.

Prompt user for height and radius of the cylinder. Store in the repective variables

Calculate Volume of the cylinder

Calculate Surface Area

Using Java's printf function to output result to 2 decimal places

User Neil Billingham
by
6.7k points