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:

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    
	    Scanner input = new Scanner(System.in);
	    double radius;
		System.out.print("Please enter Radius: ");
		
		radius = input.nextDouble();
		input.close();
		
		System.out.println("Area of circle: " + (Math.PI * Math.pow(radius, 2)));
		System.out.println("Circumference of circle: " + (2 * Math.PI * radius));
		System.out.println("Volume of sphere: " + (4.0 / 3.0 * Math.PI * Math.pow(radius, 3)));
		System.out.println("Surface area of sphere: "+ (4.0 * Math.PI * Math.pow(radius, 2)));
	    
	}
}
Related Content