-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPP2_9
More file actions
27 lines (23 loc) · 851 Bytes
/
PP2_9
File metadata and controls
27 lines (23 loc) · 851 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
import java.text.DecimalFormat;
import java.lang.Math;
import java.util.Scanner;
public class radius
{
public static void main (String[] args)
{
//double
final double VOLUME, SURFACE_AREA;
double pi = Math.PI;
//scanner
Scanner keyboard = new Scanner(System.in);
System.out.print("What is the radius? ");
int r = keyboard.nextInt();
//math
VOLUME = (double)(pi * Math.pow(r, 3) * 3/4);
SURFACE_AREA = (double)(4 * pi * Math.pow(r, 2));
// four decimal places
DecimalFormat decimal = new DecimalFormat("0.####");
//print volume and surface area
System.out.println("The volume is " + decimal.format(VOLUME) + " The surface area is " + decimal.format(SURFACE_AREA));
} //end main
} //end class radius