Java入门:基础算法之计算三角形面积 |
您所在的位置:网站首页 › java怎样算入门 › Java入门:基础算法之计算三角形面积 |
本部分介绍如何计算三角形面积。 /** * @author: 理工云课堂 * @description: 程序计算三角形的面积.三角形的底和高由用户输入 */ import java.util.Scanner; class AreaTriangleDemo { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the width of the Triangle:"); double base = scanner.nextDouble(); System.out.println("Enter the height of the Triangle:"); double height = scanner.nextDouble(); //面积 = (width*height)/2 double area = (base* height)/2; System.out.println("Area of Triangle is: " + area); } }输出 Enter the width of the Triangle: 2 Enter the height of the Triangle: 2 Area of Triangle is: 2.0
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |