Find volume of cube using Math class - Java

Below is a simple java program which will use Java.Math class to find volume of a cube.
The diameter of the Sun is approximately 865,000 miles. The diameter of the Earth is approximately 7,600 miles. Use the methods in the class Math to calculate:
(a) The volume of the Earth in cubic miles
(b) The volume of the Sun in cubic miles
(c) The ratio of the volume of the Sun to the volume of the Earth



class fourthappagain
{
    public static void main(String args[])
    {
        double diaofsun = 865000, diaofearth=7600;
        double volumeofearth = ( 4.0 / 3.0 ) * Math.PI * Math.pow( diaofearth/2, 3 );
        double volumeofsun = ( 4.0 / 3.0 ) * Math.PI * Math.pow( diaofsun/2, 3 );       
        System.out.println("\nVolume of Earth :: "+volumeofearth);
        System.out.println("\nVolume of Sun :: "+volumeofsun);       
        System.out.println("\nRation Sun:earth :: "+volumeofsun/volumeofearth+":1");
      }
}



Post a Comment