Computer Science, asked by hhhhyyrfft, 1 year ago

Write a program to enter the sides of a triangle and find wheather the triangle is possible or not

Answers

Answered by Anonymous
6

import java.util.*;

public class Triangle

{

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

float a,b,c;

System.out.println("Enter the length of the sides of the triangle");

a=in.nextFloat();

b=in.nextFloat();

c=in.nextFloat();

if(a+b>c && a+c>b && b+c>a)

{

System.out.println("Triangle is possible");

}

else

{

System.out.println("Triangle is not possible");

}

}

}

Answered by jack6778
9

Example

Input

Input first side: 7

Input second side: 10

Input third side: 5

Output

Triangle is valid

Required knowledge

Basic C programming, Relational operators, Nested If else

Property of triangle

Validity of triangle with side

A triangle is valid if sum of its two sides is greater than the third side. Means if a, b, c are three sides of a triangle. Then the triangle is valid if all three conditions are satisfied

a + b > c

a + c > b and

b + c > a

Similar questions