-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcylinder.java
34 lines (22 loc) · 845 Bytes
/
cylinder.java
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
30
31
32
33
34
import java.util.Random;
public class cylinder {
/* Program that generates a random integer radius(r) and height(h)
for a cylinder range 1 to 20 inclusive and then computes the volume
and surface area of the cylinder.
*/
public static void main(String[] args)
{
Random generator = new Random();
final double pi = 3.14;
int r, h;
double volume, surface_area;
r = generator.nextInt(20) + 1 ;
h = generator.nextInt(20) + 1 ;
volume = pi * r * r * h;
surface_area = 2 * pi * r * h;
System.out.println("random radius:" + r );
System.out.println("random Height:" + h );
System.out.println("Volume of Cylinder:" + volume );
System.out.println("Surface Area of Cylinder:" + surface_area );
}
}