ADVERTISEMENT
ADVERTISEMENT

Java program to calculate the surface area and volume of Sphere

Given the value of radius, we have to calculate the surface area and volume of Sphere.
Submitted by Nidhi, on February 28, 2022

Problem Solution:

In this program, we will read the radius from the user and calculate the surface area, volume, of the Sphere.

Program/Source Code:

The source code to calculate the surface area and volume of Sphere is given below. The given program is compiled and executed successfully.

// Java program to calculate the surface area 
// and volume of Sphere

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner SC = new Scanner(System.in);

    double radius = 0;
    double volume = 0;
    double area = 0;

    System.out.printf("Enter the radius: ");
    radius = SC.nextDouble();

    volume = (4.0 / 3) * (3.14) * Math.pow(radius, 3);
    area = 4 * (3.14) * Math.pow(radius, 2);

    System.out.printf("Volume of Sphere 	  : %f\n", volume);
    System.out.printf("Surface area of Sphere: %f\n", area);
  }
}

Output:

Enter the radius: 4.56
Volume of Sphere          : 396.974776
Surface area of Sphere: 261.167616

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contains a static method main().

The main() method is an entry point for the program. Here, we read the radius from the user using the Scanner class. Then we calculated the volume and surface area of Sphere and printed the result.

Java Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.