Aim:
To write a java program to find volume of box.
Algorithm:
- Declare the class box.
- Declare height, width and depth in write data.
- Declare another class example.
- Create an object and access write data.
- 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