# Java Program to Find Volume of Prism

In the previous article we have discussed Java Program to Find Volume of Cone

## Program to Find Volume of Prism

Before going into the program, let’s see how we find the volume of Prism.

Formula for Volume of Prism = base * height

Where,

• base‘ represents area of base of prism.
• height‘ represents height of prism.

Let’s see different ways to find volume of prism.

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Approach:

1. Take user input or declare area of base and height of prism.
2. Then using the formula find the volume of prism.
3. Then display that result i.e volume.

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

import java.util.*;

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

//area of base declared
double base=6;
//height declared
double height=7;

//calculating volume using formula
double  volume=base*height ;

System.out.println("Volume Of Prism : " + volume);
}
}
Output:

Volume Of Prism : 42.0

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

import java.util.*;

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

//Taking area of base as input from user
System.out.println("Enter area of base of prism : ");
double base=s.nextDouble();
//Taking height as input from user
System.out.println("Enter height of prism : ");
double height=s.nextDouble();

//calculating volume using formula
double  volume=base*height ;

System.out.println("Volume Of Prism : " + volume);
}
}
Output:

Enter area of base of prism : 6
Enter height of prism : 7
Volume Of Prism : 42.0

### Method-3: Java Program to Find Volume of Prism By User Defined Method

import java.util.*;

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

//Taking area of base as input from user
System.out.println("Enter area of base of prism : ");
double base=s.nextDouble();
//Taking height as input from user
System.out.println("Enter height of prism : ");
double height=s.nextDouble();
findVolume(base,height);
}

//user defined method
//this method will find the volume of the prism
public static void findVolume(double base, double height)
{
//calculating volume using formula
double  volume=base*height ;

System.out.println("Volume Of Prism : " + volume);
}
}
Output:

Enter area of base of prism : 6
Enter height of prism : 7
Volume Of Prism : 42.0

Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well.

Related Java Programs: