直方体の表面積と体積を見つけるJavaプログラム
この記事では、直方体の表面積と体積を計算する方法を理解します。直方体は、長方形の6つの面を持つ3次元オブジェクトです。つまり、辺の長さと幅が異なります。立方体と直方体の違いは、立方体の長さ、高さ、幅が等しいのに対し、直方体ではこれら3つは同じではないことです
直方体の表面積は、式-
を使用して計算されます。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);
}
} 出力
Volume Of the Cuboid is : 336.0 Surface area Of the Cuboid is : 292.0
-
正方形の領域を見つけるJavaプログラム
この記事では、正方形の面積を見つける方法を理解します。正方形の面積は、次の式を使用して計算されます- side*side i.e. s2 以下は同じのデモンストレーションです- 正方形の辺がsの場合、正方形の面積はs 2で与えられます。 − 入力 入力が-であると仮定します Length of the side : 4 出力 必要な出力は-になります Area of the square : 16 アルゴリズム Step 1 - START Step 2 - Declare 2 integer values namely my_side and my_area. S
-
長方形の周囲を見つけるJavaプログラム
この記事では、長方形の周囲を見つける方法を理解します。長方形の周囲長は、長方形のすべての辺の長さを加算して計算されます。 以下は長方形のデモンストレーションです。長方形の周囲は、長方形の2つの長さと2つの幅の全長です- 入力 入力が-であると仮定します The length of the sides of a rectangle are : 5, 8, 5, 8 出力 必要な出力は-になります Perimeter : 26 アルゴリズム Step 1 – START Step 2 – Declare 5 floating point variabl