write a program to test whether 3 given side form a triangle or not.
Answers
This theorem simply states that the sum of two sides of a triangle must be greater than the third side. If this is true for all three combinations, then you will have a valid triangle. You'll have to go through these combinations one by one to make sure that the triangle is possible.
Condition on the sides. The triangle inequality states that the sum of the lengths of any two sides of a triangle must be greater than or equal to the length of the third side. That sum can equal the length of the third side only in the case of a degenerate triangle, one with collinear vertices.
Answer:
import.java.util.Scanner ;
public class TriangleTest
{
public static boolean CanMake(int s1, int s2, int s3)
{
boolean result;
if (s1 + s2 > s3 && s2 + s3 > s1 && s3+s1>s2)
result = true;
else
result = false;
return result;
}
public static void main (String[ ] arts)
{
Scanner sc = new Scanner (System.in) ;
int side 1, side 2, side 3 ;
System.out.println("Enter 3 sides") ;
Side 1 = sc.nextInt( ) ;
Side 2 = sc.nextInt( ) ;
Side 3 = sc.nextInt( ) ;
if (CanMake (side1, side2, side 3) == true)
System.out.println("Given 3 sides will make a triangle");
else
System.out.println("Given 3 sides cannot make a triangle");
}
}
Example Output :
Enter 3 sides
10 14 12
Given 3 sides will make a triangle