Volume of sphere by using Java program
Answers
Answer:
import java.util.Scanner;//to accept values from the user
class volume
{
public static void main()
{
Scanner sc=new Scanner(System.in);//calling the function
System.out.println("Enter the radius");//asking the user to enter the radius
double r=sc.nextDouble();//accepting the radius
double vol=4/3*3.14*r*r*r;//calculating the volume
System.out.println("The volume of the sphere is: " + vol);/*displaying the volume*/
}//main ends here
}//class ends here
Answer:
import java.util.*;
public class VOLUME_OF_SPHERE
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double r,v=0;
System.out.println("Enter the radius of the sphere:");
r=sc.nextDouble();
r=Math.pow(r,3);
v=(4/3)*Math.PI*r;
System.out.println("Volume of sphere:"+v);
}
}
Hope it helps. Happy to help mate.
Explanation: