TECHNOLOGIES:

# Check triangle is valid or not when sides are given

Article:
Viewed:  1772
Posted On:  24/07/2013 03:48:29
Hi all,With the help of this article i am going to tell you that how we can find out that the triangle is valid or not when sides are givenby the user .....................

Below is my code:

import java.util.Scanner;
class triangle
{
public static void main(String s[])
{
int a,b,c;
System.out.println("enter 1 side of triangle ");
Scanner scan=new Scanner(System.in);
a=scan.nextInt();
System.out.println("you entered ="+a);
System.out.println("enter 2 side of triangle");
Scanner scan1=new Scanner(System.in);
b=scan1.nextInt();
System.out.println("you entered ="+b);
System.out.println("enter 3side of triangle");
Scanner scan2=new Scanner(System.in);
c=scan2.nextInt();
System.out.println("you entered ="+c);
if(a>b+c)
{
System.out.println("triangle is valid");
}
else if(b>a+c)
{
System.out.println("triangle is valid");
}
else if(c>b+a)
{
System.out.println("triangle is valid");
}
else
{
System.out.println("triangle is invalid");
}
}
}

Step 1:
After writing this in notepad save the file with the name followed by (.java) for eg. I saved it with triangle.java

Step 2 :
Open command prompt

Step 3
: Write javac triangle.java - Press Enter for compilation

Step 4 :
Write java triangle for execution

O
utput:

Image 1.

 Comment: