📜  求长方体体积和表面积的Java程序

📅  最后修改于: 2022-05-13 01:55:35.433000             🧑  作者: Mango

求长方体体积和表面积的Java程序

Cuboid是在 3 维平面中表示的 3 维盒状图形。一个长方体有 6 个矩形面。每张脸都以 90 度与另一张脸相遇长方体的三个边在同一个顶点相交。由于它是由6个矩形面组成的,所以它不同尺寸的长、宽、高。给定长方体的尺寸,求长方体的表面积和体积。下面给出了计算面积和体积的公式。

例子:

Input : 20 15 10
Output : Surface Area = 1300
         Volume = 3000 
  

Input : 30 5 10
Output : Surface Area = 1000
         Volume = 1500

公式:

方法 :

  • 给定圆锥的尺寸,比如说长方体的长 L、高 H 和宽 B。
  • 计算体积和表面积

示例 1:

Java
// Java Program to Find the Volume and Surface Area of
// Cuboids
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // specify L,B and H
        double L = 20, B = 15, H = 10;
        
        // calculate SurfaceArea
        double SurfaceArea = 2 * (L * B + B * H + H * L);
        
        // calculate Volume
        double Volume = L * B * H;
        
        System.out.println(
            "The Surface area of cuboid is : "
            + SurfaceArea);
        
        System.out.println("The Volume of the cuboid is : "
                           + Volume);
    }
}


Java
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // specify L,B and H
        double L = 30, B = 5, H = 10;
        
        // calculate SurfaceArea
        double SurfaceArea = 2 * (L * B + B * H + H * L);
        
        // calculate Volume
        double Volume = L * B * H;
        
        System.out.println(
            "The Surface area of cuboid is : "
            + SurfaceArea);
        
        System.out.println("The Volume of the cuboid is : "
                           + Volume);
    }
}


输出
The Surface area of cuboid is : 1300.0
The Volume of the cuboid is : 3000.0

示例 2:

Java

import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // specify L,B and H
        double L = 30, B = 5, H = 10;
        
        // calculate SurfaceArea
        double SurfaceArea = 2 * (L * B + B * H + H * L);
        
        // calculate Volume
        double Volume = L * B * H;
        
        System.out.println(
            "The Surface area of cuboid is : "
            + SurfaceArea);
        
        System.out.println("The Volume of the cuboid is : "
                           + Volume);
    }
}
输出
The Surface area of cuboid is : 1000.0
The Volume of the cuboid is : 1500.0

时间复杂度 = O(n)