Pls answer correctly ☺️
Answers
Solution:
The given problem is solved in Java.
import java.util.Scanner;
public class isTrianglePossible{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int a,b,c;
System.out.print("Enter first side: ");
a=sc.nextInt();
System.out.print("Enter second side: ");
b=sc.nextInt();
System.out.print("Enter second side: ");
c=sc.nextInt();
sc.close();
if(a+b>c&&b+c>a&&a+c>b)
System.out.println("Triangle is possible.");
else
System.out.println("Triangle is not possible.");
}
}
Logic:
Let three sides of triangle be x, y and z.
The triangle can be formed if and only if - (x + y > z) and (y + z > x) and (z + x > y)
If all the three conditions is satisfied, then the triangle is possible.
So, to solve this,
(1) Accept three sides.
(2) Check if the condition is satisfied.
(3) If true, print "triangle is possible".
(4) If false, print "triangle is not possible".
See attachments for output.