In the previous article, we have seen Java Program to Find Maximum Volume of Cuboid that can be Achieved with Given Sum of Sides

In this article we are going to see how to find the volume of ellipsoid using Java programming language.

## Java Program to Find Volume of Ellipsoid

Before Jumping into the program directly let’s see how we can find the volume of ellipsoid.

**Explanation:**

Formula to find volume of ellipsoid = (4/3) * pie * x * y * z

Where,

- x represents the radius value in x-axis.
- y represents the radius value in y-axis.
- z represents the radius value in z-axis.

**Example: **

Let x-axis of ellipsoid = 1 y-axis of ellipsoid = 1 z-axis of ellipsoid = 1 So, vol. of ellipsoid = (4/3) * pie * x * y * z => 4/3 * 3.14 * 1 * 1 * 1 = 4.18

### Method-1: Java Program to Find Volume of Ellipsoid By Using Static Value

**Approach:**

- Declare an integer variable say ‘
`x`

’ and assign the value to it, which holds the x-axis value of ellipsoid(radius). - Declare an integer variable say ‘
`y`

’ and assign the value to it, which holds the y-axis value of ellipsoid(radius). - Declare an integer variable say ‘
`z`

’ and assign the value to it, which holds the z-axis value of ellipsoid(radius). - Declare the value of pie i.e. 3.14
- Find the volume of ellipsoid using the formula
`(4/3) * pie * x * y * z`

- Print the result.

**Program:**

class Main { public static void main(String [] args) { //length of 3 independent axes are declared int x = 1; int y = 1; int z = 1; //pie value declared double pie = 3.14; //finding volume double vol = (4 * pie * x * y * z)/3; System.out.println("The volume of ellipsoid is:" + vol); } }

Output: The volume of ellipsoid is: 4.1866666666666665

### Method-2: Java Program to Find Volume of Ellipsoid By Using User Input Value

**Approach:**

- Declare an integer variable say ‘
`x`

’ and take the value as user input, which holds the x-axis value of ellipsoid(radius). - Declare an integer variable say ‘
`y`

’ and take the value as user input, which holds the y-axis value of ellipsoid(radius). - Declare an integer variable say ‘
`z`

’ and take the value as user input, which holds the z-axis value of ellipsoid(radius). - Declare the value of pie i.e. 3.14
- Find the volume of ellipsoid using the formula
`(4/3) * pie * x * y * z`

- Print the result.

**Program:**

import java.util.*; class Main { public static void main(String [] args) { //Scanner class object is created Scanner s = new Scanner(System.in); //length value of 3 independent axes are taken as user input System.out.println("Enter the value of x asis:"); int x = s.nextInt(); System.out.println("Enter the value of y asis:"); int y = s.nextInt(); System.out.println("Enter the value of z asis:"); int z = s.nextInt(); //pie value declared double pie = 3.14; //finding volume double vol = (4 * pie * x * y * z)/3; System.out.println("The vol of elipsoid is:" + vol); } }

Output: Enter the value of x asis: 2 Enter the value of y asis: 3 Enter the value of z asis: 4 The vol of elipsoid is:100.48

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

**Related Java Articles:**