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.