JAVA 上机作业5.19

/*   
* Copyright (c) 2015,烟台大学计算机学院   
* All right reserved.   
* 文件名:MyTriangle.java  
* 作者:柴银平   
* 完成时间:2015年10月13日   
* 版本号:v1.0
* 
*   
* 问题描述:输入三个小数来构成三角形的三边,若成立则输出该三角形的面积
*   
* 程序输入:输入三个小数
* 
* 程序输出: 输出是否构成三角形以及构成的三角形的面积
*/
import java.util.Scanner;


public class MyTriangle {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Please enter three decimals as the triangle's three sides:");
		Scanner input=new Scanner(System.in);
		double a=input.nextDouble();
		double b=input.nextDouble();
		double c=input.nextDouble();
		boolean s=isValid(a,b,c);
		if(s==true)
		{	System.out.println("There can build an triangle");
		    System.out.println("This triangle's area is "+area(a,b,c));
		}
		else
			System.out.println("There cann't build an triangle");
	}
public static boolean isValid(double side1, double side2, double side3){
	if ((side1+side2>side3)&&(side1+side3>side2)&&(side2+side3>side1))
		return true;
	else
		return false;
}
public static double area(double side1, double side2, double side3){
	double a=(side1+side2+side3)/2;
	return Math.sqrt(a*(a-side1)*(a-side2)*(a-side3));
}

}


测试图示:


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值