WAP in java to input length breadth and height and calculate the total surface area and volume of a Cuboid. doing with importing scanner
Answers
Answer:
Java Program to find Volume and Surface Area of Cuboid
Write Java Program to find Volume and Surface Area of Cuboid with example. Before we step into the Java Program to find Volume and Surface Area of Cuboid, Let see the definitions and formulas behind the Area of Top & Bottom Surfaces, Surface area of a Cuboid, Lateral Surface Area and Volume of a Cuboid
Java Cuboid
A Cuboid is a 3D object made up of 6 Rectangles. All the opposite faces (i.e., Top and Bottom) are equal.
Java Surface Area of a Cuboid
The Total Surface Area of a Cuboid is the sum of all the six rectangles areas present in the Cuboid. If we know the length, width, and height of the Cuboid then we can calculate the Total Surface Area using the formula:
Area of Top & Bottom Surfaces = lw + lw = 2lw
Area of Front & Back Surfaces = lh + lh = 2lh
The Area of both sides = wh + wh = 2wh
The Total Surface Area of a Cuboid is the sum of all the 6 faces. So, we have to add all these areas to calculate the final Surface Area
Total Surface Area of a Cuboid = 2lw + 2lh + 2wh
It is equal: Total Surface Area = 2 (lw + lh +wh)
The Java volume of a Cuboid
The amount of space inside the Cuboid is called Volume. If we know the length, width, and height of the Cuboid then we can calculate the volume using the formula:
Volume of a Cuboid = Length * Breadth * Height
The volume of a Cuboid = lbh
The Lateral Surface Area of a Cuboid = 2h (l + w).
Java Program to find Volume and Surface Area of Cuboid
This Java program allows users to enter the length, width, and height of a Cuboid. Next, the Java program will calculate the Volume, Surface Area, and Lateral Surface Area of Cuboid as per the formulas.
// Java Program to find Volume and Surface Area of Cuboid
package SurfaceAreaPrograms;
import java.util.Scanner;
public class VolumeOfCuboid {
private static Scanner sc;
public static void main(String[] args) {
// LSA = Lateral Surface Area of a Cube, SA = Surface Area
float length, width, height, SA, Volume, LSA;
sc = new Scanner(System.in);
System.out.println("\n Please Enter the Length of a Cuboid : ");
length = sc.nextFloat();
System.out.println("\n Please Enter the Width of a Cuboid : ");
width = sc.nextFloat();
System.out.println("\n Please Enter the Height of a Cuboid : ");
height = sc.nextFloat();
SA = 2 * (length * width + length * height + width * height);
Volume = length * width * height;
LSA = 2 * height * (length + width);
System.out.format("\n The Surface area of a Cuboid = %.2f", SA);
System.out.format("\n The Volume of a Cuboid = %.2f", Volume);
System.out.format("\n The Lateral Surface area of a Cuboid = %.2f", LSA);
}
}
OUTPUT
Java Program to find Volume and Surface Area of Cuboid 1
ANALYSIS
The following statement will allow the user to enter the length, width, and height of a cuboid. Then we are assigning the user entered values to already declared a variable called length, width, and height.
System.out.println("\n Please Enter the Length of a Cuboid : ");
length = sc.nextFloat();
System.out.println("\n Please Enter the Width of a Cuboid : ");
width = sc.nextFloat();
System.out.println("\n Please Enter the Height of a Cuboid : ");
height = sc.nextFloat();
Next, we are using the Mathematical Formula to calculate the surface area of a Cuboid
SA = 2 * (length * width + length * height + width * height);
In the next Java line, We are calculating the volume of a Cuboid
Answer:
import java.util.Scanner;
class Cuboid{
public static void main (String args[]){
int a,b,c,area;
Scanner sc=new Scanner (System.in);
a=sc.nextInt("Enter length");
b=sc.nextInt("Enter breadth");
c=sc.nextInt("enter height");
area=a*b*c;
System.out.println("Area of the cuboid is : ",area);
}
}