forked from jsquared21/Intro-to-Java-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_02_02.java
More file actions
executable file
·29 lines (25 loc) · 857 Bytes
/
Exercise_02_02.java
File metadata and controls
executable file
·29 lines (25 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
(Compute the volume of a cylinder) Write a program that reads in the radius
and length of a cylinder and computes the area and volume using the following
formulas:
area = radius * radius * pi
volume = area * length
*/
import java.util.Scanner;
public class Exercise_02_02 {
public static void main(String[] args) {
// Create a Scanner object
Scanner input = new Scanner(System.in);
final double PI = 3.14159265359;
// Prompt user to enter the radius and length of a cylinder
System.out.print("Enter the radius and length of a cylinder: ");
double radius = input.nextDouble();
double length = input.nextDouble();
// Comput the area and volume
double area = radius * radius * PI;
double volume = area * length;
// Display results
System.out.println("The area is " + area);
System.out.println("The volume is " + volume);
}
}