Java Function to test for a valid triangle.

//Java Function to test for a valid triangle.



import java.util.Scanner;

public class Program 
{   
    	public static void main( String[] args ) 
    	{
		Scanner reader = new Scanner(System.in);
		int a,b,c,find;
		System.out.print("Enter 3 side of triangle A B C : \n");
		a = reader.nextInt(); 
		b = reader.nextInt();
		c = reader.nextInt();
		find=IsTriangle(a,b,c);
		if(find==1)
			System.out.print("\nValid triangle ");
		else
			System.out.print("\nInvalid triangle ");
   	}
   	public static int IsTriangle(int a,int b,int c)
   	{	
		
    		int chk;
		if(a+b>c && a+c>b && b+c>a)
			chk=1;
		else
			chk=0;
		return chk;
   	}
	
}

Output :
Enter 3 side of triangle A B C :
5
6
6

Valid triangle



Leave a comment