mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 17:29:31 +08:00
Add Tests for Heron's Formula (#3035)
This commit is contained in:
19
src/main/java/com/thealgorithms/maths/HeronsFormula.java
Normal file
19
src/main/java/com/thealgorithms/maths/HeronsFormula.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
/**
|
||||
* Find the area of a triangle using only side lengths
|
||||
*/
|
||||
|
||||
public class HeronsFormula {
|
||||
|
||||
public static double Herons(int s1, int s2, int s3)
|
||||
{
|
||||
double a = s1;
|
||||
double b = s2;
|
||||
double c = s3;
|
||||
double s = (a + b + c)/2.0;
|
||||
double area = 0;
|
||||
area = Math.sqrt((s)*(s-a)*(s-b)*(s-c));
|
||||
return area;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user