Created
June 2, 2018 19:10
-
-
Save thmain/df944de1bc07b7b2d91343453541dc63 to your computer and use it in GitHub Desktop.
This file contains 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
public class CheckTriangle { | |
public static void checkTriangleFormed(double a, double b, double c){ | |
//check all combinations, | |
//sum of any 2 sides must be greater than the third side to form a triangle | |
if(check(a, b, c) && check(a, c, b) && check(b, c, a)) | |
System.out.println("Triangle can be formed using side " + a + ", " + b + ", " +c ); | |
else | |
System.out.println("Triangle cannot be formed using side " + a + ", " + b + ", " +c ); | |
} | |
public static boolean check(double x, double y, double z){ | |
//check if sum of x and y is greater than z | |
if((x+y)>z) | |
return true; | |
System.out.println("Sum of " + x + " and "+ y + " is not > " + z); | |
return false; | |
} | |
public static void main(String[] args) { | |
double a = 2.5; | |
double b = 3.5; | |
double c = 5; | |
checkTriangleFormed(a, b, c); | |
System.out.println("________________________"); | |
a = 1; | |
b = 3; | |
c = 5; | |
checkTriangleFormed(a, b, c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment