Answer:
import java.util.Scanner;
public class triangle {
public static void main (String [] args) {
int sideOne, sideTwo, sideThree;
Scanner in = new Scanner (System.in);
System.out.println("Enter the first side of the triangle");
sideOne = in.nextInt();
System.out.println("Enter the secon side of the triangle");
sideTwo = in.nextInt();
System.out.println("Enter the third side of the triangle");
sideThree = in.nextInt();
if ( sideOne<=0||sideTwo<=0|| sideThree<=0){
System.out.println(" The Values enter are "+sideOne+ "," +sideThree+ ","+sideThree+ " These values don't make a valid triangle");
}
else if ((sideOne + sideTwo> sideThree) || (sideOne+sideThree > sideTwo) || (sideThree+sideTwo > sideOne))
{
System.out.println ("The triangle is Valid");
}
else {
System.out.println(" The Values enter are "+sideOne+ "," +sideTwo+ ","+sideThree+ " These values don't make a valid triangle");
}
}
Explanation:
for a Triangle to be Valid one of the three sides of the triangle must greater than the other two sides. The code above enforces this condition using an if statement in combination with the Or Operator
The following conditions where enforced
side one, side two and side three != 0
Side One + Side Three > Side Two
Side Three + Side Two> Side One
Side Two + Side One > Side Three