Java
 Computer >> コンピューター >  >> プログラミング >> Java

台形の領域を見つけるJavaプログラム


この記事では、台形の領域を見つける方法を理解します。台形は、少なくとも1対の辺が互いに平行な四辺形の一種です。台形の平行な側面はベースと呼ばれ、台形の非平行な側面は脚と呼ばれます。台形とも呼ばれます。

台形の面積は、式-

を使用して計算されます。
(height/2 * (side_1 + side_2).
i.e.
Area = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel
sides

以下は同じもののデモンストレーションです。平行な辺aとbの長さと台形の高さhの台形の面積は、-

で与えられます。

台形の領域を見つけるJavaプログラム

入力

入力が-

であると仮定します
side_1 = 5
side_2 = 6
height = 6

出力

必要な出力は-

になります
Area of trapezium is: 33.0

アルゴリズム

Step 1 - START
Step 2 – Declare three integer values namely side_1 , side_2 and height. Declare a float value
namely my_area.
Step 3 - Read the required values from the user/ define the values
Step 4 – Calculate the area of the trapezium using the formula (height/2 * (side_1 + side_2)
and store the result
Step 5- Display the result
Step 6- Stop

例1

ここでは、プロンプトに基づいてユーザーが入力を入力しています。この例は、コーディンググラウンドツールでライブで試すことができます 台形の領域を見つけるJavaプログラム

import java.util.Scanner;
public class AreaOfTrapezium {
   public static void main(String args[]){
      int side_1 , side_2 , height ;
      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.print("Enter the length of the first parallel side: ");
      side_1 = my_scanner.nextInt();
      System.out.print("Enter the length of the first parallel side : ");
      side_2 = my_scanner.nextInt();
      System.out.print("Enter the heigth of the trapezium : ");
      height = my_scanner.nextInt();
      float my_area = (height/2 * (side_1 + side_2));
      System.out.println("The area of trapezium is: " + my_area);
   }
}

出力

Required packages have been imported
A reader object has been defined
Enter the length of the first parallel side: 5
Enter the length of the first parallel side : 6
Enter the heigth of the trapezium : 6
The area of trapezium is: 33.0

例2

ここでは、整数は事前に定義されており、その値にアクセスしてコンソールに表示されます。

public class AreaOfTrapezium {
   public static void main(String args[]){
      int side_1 = 5, side_2 = 6, height = 6;
      System.out.println("The sides and height of the trapezium is defined as " +side_1 + ", " + side_2 + " and " + height);
      float my_area = (height/2 * (side_1 + side_2));
      System.out.println("The area of Trapezium is: " + my_area);
   }
}

出力

The sides and height of the trapezium is defined as 5, 6 and 6
The area of Trapezium is: 33.0

  1. 正方形の領域を見つける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

  2. 長方形の周囲を見つける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