Coding Lab - TechOnTechnology

Java recursive program to find the volume of a box. Use constructors to initialize the width, height and breadth.




import java.io.*;
class volofbox{
double width,height,breadth;
volofbox(double x,double y,double z)   /*constructor */
{
width=x;
height=y;
breadth=z;
}
    public static void main(String[] args) throws IOException
    {
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.println("\nCALCULATE VOLUME OF A BOX :");
        System.out.print("\nENTER WIDTH : ");       
        double a = Integer.parseInt(in.readLine());
        System.out.print("ENTER HEIGHT : ");       
        double b = Integer.parseInt(in.readLine());
        System.out.print("ENTER BREADTH : ");       
        double c = Integer.parseInt(in.readLine());

        volofbox v=new volofbox(a,b,c);    /* calling constructor with parameter a,b,c */
        System.out.print("\nVOLUME OF A BOX : "+(v.width*v.height*v.breadth)+"\n");
    }
}

Name

Email *

Message *