ในบทความนี้ เราจะเข้าใจวิธีการคำนวณพื้นที่ผิวและปริมาตรทรงลูกบาศก์ ทรงลูกบาศก์เป็นวัตถุสามมิติที่มีหน้าหกเหลี่ยมหกหน้า ซึ่งหมายความว่ามีด้านยาวและด้านกว้างต่างกัน ความแตกต่างระหว่างลูกบาศก์กับทรงลูกบาศก์คือลูกบาศก์มีความยาว ความสูง และความกว้างเท่ากัน ในขณะที่ลูกบาศก์ทั้งสามนั้นไม่เหมือนกัน
พื้นที่ผิวของทรงลูกบาศก์คำนวณโดยใช้สูตร −
2*( length *width + width* height + height*length)
พื้นที่ของทรงลูกบาศก์คำนวณโดยใช้สูตร −
length*width*height
ด้านล่างนี้เป็นการสาธิตสิ่งเดียวกัน -

ป้อนข้อมูล
สมมติว่าข้อมูลที่เราป้อนคือ −
Length= 6; Width= 7; Height= 8;
ผลผลิต
ผลลัพธ์ที่ต้องการจะเป็น −
Volume Of the Cuboid is : 336.0 Surface area Of the Cuboid is : 292.0
อัลกอริทึม
Step 1 - START Step 2 - Declare five double values namely my_length, my_width, my_height, my_volume, my_surface_area Step 3 - Read the required values from the user/ define the values Step 4 - Use the formula 2*( length *width + width* height + height*length) to calculate the surface area of cuboid Step 5 - Use the formula length*width*height to calculate the area of the cuboid Step 6 - Display the result Step 7 - Stop
ตัวอย่างที่ 1
ที่นี่ ผู้ใช้ป้อนอินพุตตามข้อความแจ้ง คุณสามารถลองใช้ตัวอย่างนี้ในเครื่องมือกราวด์ของเรา
.
import java.util.Scanner;
public class VolumeOfCuboid{
public static void main(String args[]){
double my_length, my_width, my_height, my_volume, my_surface_area;
System.out.println("Required packages have been imported");
Scanner my_scanner = new Scanner(System.in);
System.out.println("A reader object has been defined ");
System.out.println("Enter the length of Cubiod:");
my_length=my_scanner.nextDouble();
System.out.println("Enter the width of Cubiod:");
my_width=my_scanner.nextDouble();
System.out.println("Enter height of Cubiod:");
my_height=my_scanner.nextDouble();
my_volume= my_length*my_width*my_height;
System.out.println("The volume Of the Cuboid is :" +my_volume);
my_surface_area =2*( my_length *my_width + my_width* my_height + my_height*my_length);
System.out.println("The surface area Of the Cuboid is : " +my_surface_area);
}
} ผลลัพธ์
Required packages have been imported A reader object has been defined Enter the length of Cubiod: 6 Enter the width of Cubiod: 7 Enter height of Cubiod: 8 The volume Of the Cuboid is : 336.0 The surface area Of the Cuboid is : 292.0
ตัวอย่างที่ 2
ในที่นี้ มีการกำหนดจำนวนเต็มก่อนหน้านี้ และเข้าถึงและแสดงค่าบนคอนโซล
public class VolumeOfCuboid{
public static void main(String args[]){
double my_length, my_width, my_height, my_volume, my_surface_area;
my_length= 6;
my_width= 7;
my_height= 8;
my_volume= my_length*my_width*my_height;
System.out.println("The volume Of the Cuboid is:" +my_volume);
my_surface_area =2*( my_length *my_width + my_width* my_height + my_height*my_length);
System.out.println("The surface area Of the Cuboid is:" +my_surface_area);
}
} ผลลัพธ์
The volume Of the Cuboid is:336.0 The surface area Of the Cuboid is:292.0