CSCI-2467 Lab 1 – Calculate Volume of a Cylinder
Background
The formula for the volume of a cylinder of radius r and height h is: πr2h
Assignment
Write a Java program that asks the user for the radius and height of a cylinder. The program should then calculate and print the volume of the cylinder. Be sure to include a comment in your code with your name, date, and the purpose of the program.
Start your program as follows:
package edu.cscc;
import java.lang.Math;
import java.util.Scanner;
// TODO - add a comment with your name, date, and program purpose here
public class Main {
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
double radius, height, volume;
// TODO - write your program here
}
}
Use the built-in Java constant Math.PI for the value of π.
Example Output
Enter the radius of the cylinder: 2
Enter the height of the cylinder: 10
The volume of the cylinder is: 125.66370614359172
Sample Solution