Search This Blog

Showing posts with label triangle sides. Show all posts
Showing posts with label triangle sides. Show all posts

Java Program to Check Whether It Is Possible to Draw a Triangle with Given Sides

For existence of a triangle there is a condition. The condition is 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. If the sum of the lengths of any two sides of a triangle is equal to the length of the third side, it forms a triangle with zero area. The vertices are collinear in that case. Still we can say that the triangle exists. So, here we will see a java program to check whether a triangle exists or not with given sides. The program is as follows:

import java.util.Scanner;

public class TriangleSide {
public static void main(String[] arg)
    {
    
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the sides of triangle");
    int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
    if(a+b>=c&&b+c>=a&&c+a>=b)
        System.out.println("possible");
    else
        System.out.println("impossible");
    }
}