We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ef10bb9 commit 2df4690Copy full SHA for 2df4690
src/main/java/com/thealgorithms/maths/HeronsFormula.java
@@ -14,9 +14,13 @@ public class HeronsFormula {
14
* @author satyabarghav
15
*/
16
public static double Herons(double a, double b, double c) {
17
- double s = (a + b + c) / 2.0;
18
- double area = 0;
19
- area = Math.sqrt((s) * (s - a) * (s - b) * (s - c));
20
- return area;
+ if(!(a + b > c && b + c > a && c + a > b)){
+ throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
+ }else{
+ double s = (a + b + c) / 2.0;
21
+ double area = 0;
22
+ area = Math.sqrt((s) * (s - a) * (s - b) * (s - c));
23
+ return area;
24
+ }
25
}
26
0 commit comments