Java Program to Calculate the Surface Area and Volume of Sphere

You are currently viewing Java Program to Calculate the Surface Area and Volume of Sphere

Java program to calculate the surface area and volume of Sphere

// 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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply