Last active
August 29, 2015 14:19
-
-
Save jonathan-irvin/ff5454b4826f93272550 to your computer and use it in GitHub Desktop.
Valid Triangle Detector in java
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
import java.util.Scanner; | |
public class TriangleDetector { | |
public static void main(String[] args) { | |
System.out.print("Enter Edge 1: "); | |
Scanner input = new Scanner(System.in); | |
int e1 = input.nextInt(); | |
System.out.print("Enter Edge 2: "); | |
int e2 = input.nextInt(); | |
System.out.print("Enter Edge 3: "); | |
int e3 = input.nextInt(); | |
if (e1+e2 <= e3) { | |
System.out.print("This is not a valid triangle. "+e1+ "+" +e2+ "="+(e1+e2)+" and not greater than "+e3); | |
}else if (e1+e3 <= e2) { | |
System.out.print("This is not a valid triangle. "+e1+ "+" +e3+ "="+(e1+e3)+" and not greater than "+e2); | |
}else if (e2+e3 <= e1) { | |
System.out.print("This is not a valid triangle. "+e2+ "+" +e3+ "="+(e2+e3)+" and not greater than "+e1); | |
}else{ | |
System.out.print("This is a valid triangle."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment