Trong bài này, chúng ta sẽ hiểu cách tính diện tích bề mặt và thể tích của khối lập phương. Hình khối là một vật thể ba chiều có sáu mặt hình chữ nhật, có nghĩa là nó có các cạnh có chiều dài và chiều rộng khác nhau. Sự khác biệt giữa hình lập phương và hình lập phương là một hình lập phương có chiều dài, chiều cao và chiều rộng bằng nhau trong khi ở hình lập phương thì ba hình này không giống nhau
Diện tích bề mặt của hình khối được tính theo công thức -
2*( length *width + width* height + height*length)
Diện tích của hình khối được tính bằng công thức -
length*width*height
Dưới đây là một minh chứng về điều tương tự -
Đầu vào
Giả sử đầu vào của chúng tôi là -
Length= 6; Width= 7; Height= 8;
Đầu ra
Đầu ra mong muốn sẽ là -
Volume Of the Cuboid is : 336.0 Surface area Of the Cuboid is : 292.0
Thuật toán
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
Ví dụ 1
Ở đây, đầu vào đang được người dùng nhập dựa trên lời nhắc. Bạn có thể thử trực tiếp ví dụ này trong công cụ nền tảng mã hóa của chúng tôi .
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); } }
Đầu ra
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
Ví dụ 2
Ở đây, số nguyên đã được xác định trước đó và giá trị của nó được truy cập và hiển thị trên bảng điều khiển.
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); } }
Đầu ra
The volume Of the Cuboid is:336.0 The surface area Of the Cuboid is:292.0