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.