-
Notifications
You must be signed in to change notification settings - Fork 20k
Herons : Changed the signature of the function #4686
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b35d949
Made changes to the code to correct the Logic of Armstrong Number
satyabarghav 971b80a
Resolved the issues
satyabarghav de325cb
Trying to resolve the Linter error by changing Variable name
satyabarghav 6f64e8c
Changed Variable Names : trying to resolve Clang error
satyabarghav cfd26db
Chnged the signature of the function
satyabarghav 46722cb
Added the Function documentation
satyabarghav ef10bb9
Merge branch 'master' into master
satyabarghav 0108e28
Added exception for parameters
satyabarghav d91ddd6
Merge branch 'master' into master
satyabarghav 78e3662
Merge branch 'TheAlgorithms:master' into master
satyabarghav 7405568
Resolved with suggested changes
satyabarghav 14245f7
Resolved with Suggested changes
satyabarghav a16eec2
fix: use proper logic
vil02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
package com.thealgorithms.maths; | ||
|
||
/** | ||
* Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula | ||
* Find the area of a triangle using only side lengths | ||
*/ | ||
|
||
public class HeronsFormula { | ||
public final 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; | ||
/* | ||
* A function to get the Area of a Triangle using Heron's Formula | ||
* @param s1,s2,s3 => the three sides of the Triangle | ||
* @return area using the formula (√(s(s – s1)(s – s2)(s – s3))) | ||
* here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2) | ||
* @author satyabarghav | ||
*/ | ||
private HeronsFormula() { | ||
} | ||
|
||
private static boolean areAllSidesPositive(final double a, final double b, final double c) { | ||
return a > 0 && b > 0 && c > 0; | ||
} | ||
|
||
private static boolean canFormTriangle(final double a, final double b, final double c) { | ||
return a + b > c && b + c > a && c + a > b; | ||
} | ||
|
||
public static double herons(final double a, final double b, final double c) { | ||
if (!areAllSidesPositive(a, b, c) || !canFormTriangle(a, b, c)) { | ||
throw new IllegalArgumentException("Triangle can't be formed with the given side lengths"); | ||
} | ||
final double s = (a + b + c) / 2.0; | ||
return Math.sqrt((s) * (s - a) * (s - b) * (s - c)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.