package area;
/**
* 已知三角行的三边,求面积
*/
public class TriangleArea {
public static double triangleArea(double a, double b, double c) {
if(!check(a, b, c)) {
return 0.0;
}
double s = (a + b + c) / 2;
return Math.sqrt(s * (s - a) * (s - b) * (s -c));
}
private static boolean check(double a, double b, double c) {
if(a <= 0 || b <=0 || c <= 0) {
return false;
}
if((a + b) <= c || (a + c) <= b || (b + c) <= a) {
return false;
}
return true;
}
public static void main(String[] args) {
double a = 0.3;
double b = 4;
double c = 5;
System.out.println(TriangleArea.triangleArea(a, b, c));
}
}