Programming Examples

Java program to accept three sides of a triangle as parameter and check whether it can form a triangle or not


Write a program to accept three sides of a triangle as parameter and check whether it can form a triangle or not. If it forms a triangle, check whether it is an acute angled, obtuse angled or right-angled triangle.

(Hint: To form a triangle, each side should be less the sum of the other two sides..

To form an acute angled triangle the square of every side should be less than the sum of the squares of the other two sides.

To form an obtuse angled triangle the square of any side should be greater than the sum of the squares of the other two sides.

To form an right angled triangle the square of any side should be equal to the sum of the squares of the other two sides.)

Solution

class Triangle
{
	public static void main(int a,int b,int c)
	{
		if(a<b+c && b<c+a & c<a+b)
		{
			if(a*a<b*b+c*c && b*b<c*c+a*a && c*c<a*a+b*b)
				System.out.println(“Acute angled triangle”);
			else if(a*a>b*b+c*c || b*b>c*c+a*a || c*c>a*a+b*b)
				System.out.println(“Obtuse angled triangle”);
			else
				System.out.println(“Right angled triangle”);
		}
		else
			System.out.println(“Does not form a triangle”);
	}
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz