码迷,mamicode.com
首页 > 编程语言 > 详细

Java入门:基础算法之计算三角形面积

时间:2016-04-05 21:30:37      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

本部分介绍如何计算三角形面积。

/**
 * @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

 

Java入门:基础算法之计算三角形面积

标签:

原文地址:http://www.cnblogs.com/bayes/p/5356906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!