Given the length of 3 sides of a triangle, check whether the triangle is valid or not.
Input Format
First and only line of input contains three integers A, B, C – length of sides of the triangle.
Constraints
1 <= A, B, C <= 109
Output Format
Print “Yes” if you can construct a triangle with the given three sides, “No” otherwise.
Inputcopy | Outputcopy |
---|---|
4 3 5 | Yes |
Explanation 0
Self Explanatory
Solutions:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int A = scanner.nextInt();
int B = scanner.nextInt();
int C = scanner.nextInt();
if (isValidTriangle(A, B, C)) {
System.out.println("Yes");
} else {
System.out.println("No");
}
scanner.close();
}
public static boolean isValidTriangle(int A, int B, int C) {
return (A + B > C) && (A + C > B) && (B + C > A);
}
}