Write a Java program to calculate total surface area of a cuboid. Here we wrote the code in three different ways with online execution tool , examples. The following program has been divided into three formats as shown in the table of contents. Check out :). If you need any more information regarding sample programs, then do contact us or leave a comment we are glad to help you out.
Before we show you example Java program to calculate a total surface area of a cuboid , you can check out the math formula and definition about an entire surface area of a cuboid. In case if you know the basics then skip this tutorial and move on to the program code.
Def : Total surface area of the cuboid ?
- The total surface area of a cuboid is the sum of areas of its six faces.
What is the formula to find the total surface area?
- Here goes the complete explanation:
Did you get an idea, right ? Here is the program by using above method.
Program # -1 using formula ( To calculate total surface area of cuboid )
[wp_ad_camp_3]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Scanner; class TotalSurfaceAreaOfCuboid { public static void main(String args[]) { Scanner s= new Scanner(System.in); System.out.println("Enter the length of Cubiod:"); double l=s.nextDouble(); System.out.println("Enter the breadth of Cubiod:"); double b=s.nextDouble(); System.out.println("Enter height of Cubiod:"); double h=s.nextDouble(); double area=(2*((l*b)+(b*h)+(h*l))); System.out.println("Total SurfaceArea Of Cuboid is:" +area); } } |
Output : ( Online execution tool soon updated )
1 2 3 4 |
Enter the length of Cuboid:1.0 Enter the breadth of Cuboid:2.0 Enter height of Cuboid:3.0 Total SurfaceArea Of Cuboid is:22.0 |
Program # – 2 ( using command line arguments )
[wp_ad_camp_3]
Here is the complete guide : Here is the complete guide on command line arguments – check here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.util.Scanner; class TotalSurfaceAreaOfCuboid1 { public static void main(String args[]) { double l=Double.parseDouble(args[0]); double b=Double.parseDouble(args[1]); double h=Double.parseDouble(args[2]) double area=(2*((l*b)+(b*h)+(h*l))); System.out.println("Total SurfaceArea Of Cuboid is:" +area); } } |
Sample Program # 3 ( Using return Invoked method )
Java Program – Here is the complete guide
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import java.util.Scanner; class TotalSurfaceAreaOfCuboid { public static void main(String args[]) { Scanner s= new Scanner(System.in); System.out.println("Enter the length of Cubiod:"); double l=s.nextDouble(); System.out.println("Enter the breadth of Cubiod:"); double b=s.nextDouble(); System.out.println("Enter height of Cubiod:"); double h=s.nextDouble(); double area=TotalSurfaceAreaOfCuboid.area(l,b,h); System.out.println("Total SurfaceArea Of Cone is:" +area); } public static double area(double l,double b,double h) { double a=(2*((l*b)+(b*h)+(h*l))); return a; } } |
1 2 3 4 |
Enter the length of Cuboid:1.0 Enter the breadth of Cuboid:2.0 Enter height of Cuboid:3.0 Total SurfaceArea Of Cuboid is:22.0 |
# Java program to calculate total surface area of cuboid #
Learn more here :