Java program that use radius to calculate area and circumference of a circle and volume and surface area of a sphere
Posted by Samath
Last Updated: February 09, 2021

Write a program that prompts the user for a radius and then prints
 • The area and circumference of a circle with that radius
 • The volume and surface area of a sphere with that radius

Example:

Please enter Radius: 25                                                                                                                                                                    
Area of circle: 1963.4954084936207                                                                                                                                                         
Circumference of circle: 157.07963267948966                                                                                                                                                
Volume of sphere: 65449.84694978735                                                                                                                                                        
Surface area of sphere: 7853.981633974483 


Code:

  1. import java.util.Scanner;
  2.  
  3. public class Main
  4. {
  5. public static void main(String[] args) {
  6. Scanner input = new Scanner(System.in);
  7. double radius;
  8. System.out.print("Please enter Radius: ");
  9. radius = input.nextDouble();
  10. input.close();
  11. System.out.println("Area of circle: " + (Math.PI * Math.pow(radius, 2)));
  12. System.out.println("Circumference of circle: " + (2 * Math.PI * radius));
  13. System.out.println("Volume of sphere: " + (4.0 / 3.0 * Math.PI * Math.pow(radius, 3)));
  14. System.out.println("Surface area of sphere: "+ (4.0 * Math.PI * Math.pow(radius, 2)));
  15. }
  16. }
Related Content