查詢三角形面積的 Java 程式


三角形面積是其底邊和高的一半乘積。因此,要計算三角形的面積。

  • 從使用者那裡獲取三角形的高。
  • 從使用者那裡獲取三角形的底邊。
  •  計算它們乘積,並將結果除以 2。
  • 列印最終結果。

示例

import java.util.Scanner;
public class AreaOfTriangle {
   public static void main(String args[]){
      int height, base, area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the height of the triangle ::");
      height = sc.nextInt();
      System.out.println("Enter the base of the triangle ::");
      base = sc.nextInt();
      area = (height* base);
      System.out.println("Area of the triangle is ::"+area);
   }
}

輸出

Enter the height of the triangle ::
14
Enter the base of the triangle ::
5
Area of the triangle is ::70

更新於: 13-3-2020

3K+ 瀏覽量

啟動你的 職業

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.