/*
Name: penis
*/
import java.util.*;
public class Triangletype {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the sides of Triangle");
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
if (a <= 0 || b <= 0 || c <= 0) {
System.out.println("Invalid Input");
} else if( isTriangle ( a, b, c) ) {
System.out.println("Yes, It's a Triangle");
String type = GetType(a, b, c);
System.out.println("Triangle type: " + type);
} else {
System.out.println("Not a Triangle");
}
}
//****************************************************
public static boolean isTriangle(int a , int b, int c ) {
if (a >= b + c || b >= a + c || c >= a + b) {
return false;
} else {
return true;
}
}
public static String GetType(int a, int b, int c) {
if (a == b && b == c) { // all equal sides
return "Equilateral";
} else if (a == b || b == c) { // most sides are equal with one greater or less than the others
return "Isosceles";
// a^2 + b^2 = c^2
} else if((a * a) + (b * b) == (c * c) || (c * c) + (a * a) == (b * b) || (b * b) + (c * c) == (a * a)) {
return "Right Angle";
} else {
return "Scalene";
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: