Write a program to check the type of a triangle in java programming.

Introduction:

Hii everyone, here we are going construct a program to check for the type of triangle.For this, you have to recall the triangle properties.We are using a function to make this program.

Description Of Program:

First of all, we have to decide the required parameters to construct the program like we are talking about triangle here so it’s but obvious to take three variables initially, then our program is user flexible so we input a scanner here.Then we made a function which is the constructor and then again made a function to check the properties of a triangle.At the end, we made the main function to conclude our program and then call the required function, here we call “triangle” and “checktriangle” function.Hope you find it helpful.                                                                                                 Thank You!.

CODE:

package oops;

import java.util.Scanner;
public class Triangle {
int a,b,c;

public Triangle(){
System.out.println(“Enter the sides of Triangle”);
Scanner s=new Scanner(System.in);
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
}

public void CheckTriangle(){
if(a==b&&b==c)
System.out.println(“Equilateral Triangle”);
else
{
if(a==b||b==c||c==a)
System.out.println(“Isosceles Triangle”);
else
System.out.println(“Scelen Traingle”);
}
if(a*a+b*b==c*c||b*b+c*c==a*a||a*a+c*c==b*b)
System.out.println(“Right Angle Triangle”);
}

public static void main(String[] args) {
Triangle t=new Triangle();
t.CheckTriangle();
}
}

OUTPUT :

 

 

 

Leave a Reply