Java Program to Find Volume of Box

Aim:

To write a java program to find volume of box.

Algorithm:

  1. Declare the class box.
  2. Declare height, width and depth in write data.
  3. Declare another class example.
  4. Create an object and access write data.
  5. Print the output.

Program:

import java.util.Scanner;
class Box{
int hegiht;
int width;
int depth;
Box(int a,int b,int c)
{
hegiht=a;
width=b;
depth=c;
}
int calvolume()
{
return hegiht*width*depth;
}
}
public class Main{
public static void main(String args[] )
{
int a,b,c;
Scanner put=new Scanner(System.in);
System.out.println("ENTER HEIGHT WIDTH AND DEPTH ");
a=put.nextInt();
b=put.nextInt();
c=put.nextInt();
Box A=new Box(a,b,c);
int volume=A.calvolume();
System.out.print("VOLUME OF BOX ="+volume);
}
}

Execution:

INPUT : 
ENTER HEIGHT WIDTH AND DEPTH :
9 3 5

OUTPUT :
VOLUME OF BOX = 135

Leave a Comment