Skip to content

Added tests for Heron's Formula + removed main() #3035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Area of a triangle using side lengths
  • Loading branch information
RaghavTaneja authored Apr 17, 2022
commit 1864d5f739743b0558499a2943f0544bc4fb83bb
27 changes: 27 additions & 0 deletions src/main/java/com/thealgorithms/maths/HeronsFormula.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.thealgorithms.maths;

/**
* Find the area of a triangle using only side lengths
*/

public class HeronsFormula {

public static void main(String[] args)
{
assert Herons(3,4,5) == 6.0;
assert Herons(24,30,18) == 216.0;
assert Herons(1,1,1) == 0.4330127018922193;
assert Herons(4,5,8) == 8.181534085976786;
}

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;
}
}