How do you create predefined math functions?

Rich V

New member
what do I write to add a line that prompts the user to enter the diameter of a sphere. Also how do I get the program to read in and store the number into a variable called diameter (you will need to declare any variables that you use). After that how do I calculate and store the radius in an appropriately named variable with the diameter twice as long as the radius. The formula for the volume of a sphere is v = 4/3 Pie r^3. For this formula I need to convert the formula to java and add a line which calculates and stores the value of volume in an appropriately named variable. Use math.PI for pie and math.pow to cube the radius. Does anybody know how to do this?

The diagram for this formula is as follows:

Diameter Volume(hand calculated) Volume(resulting output)
2
25.4
875,000
 
Back
Top