We have made the method to calculate the volume of a cuboid which takes the dimensions length, breadth and height as input and return the volume as output back to the main method.
Here is the source code of the Java Program to Illustrate a Method without Parameters and With Return Type. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
Scanner s = new Scanner(System.in);
System.out.print("enter width : ");
double width = s.nextDouble();
System.out.print("enter height : ");
double height = s.nextDouble();
System.out.print("enter depth: ");
double depth = s.nextDouble();
return width * height * depth;
public static void main(String args)
Box cuboid = new Box();
vol = cuboid.volume();
System.out.println("Volume is " + vol);
$ javac ReturnDemo.java $ java ReturnDemo enter width : 10 enter height : 2 enter depth: 23 Volume is 460.0
Sanfoundry Global Education & Learning Series – 1000 Java Programs.