The program first prompts the user to enter three sides of a triangle using the Scanner class. Then it uses a series of if statements to check the type of the triangle.
If all three sides are equal, then the program prints "Equilateral Triangle", which is a triangle with all sides of equal length. If two sides are equal, then the program prints "Isosceles Triangle", which is a triangle with two sides of equal length. Otherwise, the program prints "Scalene Triangle", which is a triangle with no sides of equal length.
This program provides a simple way to determine the type of a triangle based on its sides. However, it is important to note that this program does not check if the sides entered by the user could form a valid triangle or not, as there are conditions to be met in order for a triangle to be valid.
import java.util.Scanner; class Check_Triangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter Three Sides of Triangle :"); int side1 = input.nextInt(); int side2 = input.nextInt(); int side3 = input.nextInt(); if(side1 == side2 && side2 == side3) System.out.println("Equilateral Triangle."); else if(side1 == side2 || side1 == side3 || side2 == side3) System.out.println("Isosceles Triangle."); else System.out.println("Scalene Triangle."); } }
Enter Three Sides of Triangle : 60 45 45 Isosceles Triangle.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions