JAVA PROGRAMMING
Write a program to input length, bredth and height of a cuboid, calculate and display its area.
Answers
The given problem is solved using language - Java.
import java.util.Scanner;
public class CuboidVolume{
public static void main(){
Scanner sc=new Scanner(System.in);
double l,b,h;
System.out.print("Enter length of cuboid: ");
l=sc.nextDouble();
System.out.print("Enter breadth of rectangle: ");
b=sc.nextDouble();
System.out.print("Enter height of the rectangle: ");
h=sc.nextDouble();
sc.close();
System.out.print("The volumne of the cuboid will be: "+l*b*h+" cubic units.");
}
}
- Accept the length, breadth and height from the user.
- As we know that Volume = LBH, substitute the value into the formula and get the volume.
- Volume is calculated. So display it.
Enter length of cuboid: 10
Enter breadth of rectangle: 8
Enter height of the rectangle: 6
The volumne of the cuboid will be: 480.0 cubic units.
Prógram in Java to input length, bredth and height of a cuboid, calculate and display its area.
Note:
Area of Top & Bottom Surfaces = lw + lw = 2lw.
Area of Front & Back Surfaces = lh + lh = 2lh.
import java.util.*;
class Area
{
public static void main()
{
Scanner sc=new Scanner(System .in);
double l,w,h;
System.out.print("Enter length of cuboid: ");
l=sc.nextDouble();
System.out.print("Enter wídth of rectangle: ");
w=sc.nextDouble();
System.out.print("Enter height of the rectangle: ");
h=sc.nextDouble();
System.out.print("The area of the cuboid will be: "+2*l*w*h+2*l*h+"³");
}
}