//需要键盘录入,导入Scanner包 import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); double side1,side2,side3; side1=in.nextDouble(); side2=in.nextDouble();
时间: 2023-06-05 18:04:56 浏览: 88
java代码-实训4-3 import java.util.Scanner
side3=in.nextDouble();
if (side1 <= 0 || side2 <= 0 || side3 <= 0) {
System.out.println("输入错误,三角形边长必须大于零!");
} else if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1) {
System.out.println("输入错误,输入的三条边无法构成三角形!");
} else {
double p = (side1 + side2 + side3) / 2;
double area = Math.sqrt(p * (p - side1) * (p - side2) * (p - side3));
System.out.println("该三角形的面积为:" + area);
}
}
}
(需要键盘输入三角形的三条边长,然后计算并输出三角形的面积)
阅读全文