/*
Name: penis
Purpose: Calculates by three individual inputs if it's a triangle, prints whether it is or isn't, prints what type of triangle it is,
and it's area.
*/
import java.util.*; // Java tools
public class Triangletype {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); // Input method
System.out.println("Enter the sides of Triangle");
int a = in.nextInt(); // Get's the A input
int b = in.nextInt(); // Get's the B input
int c = in.nextInt(); // Get's the C input
if (a <= 0 || b <= 0 || c <= 0) { // If the inputs are a 0 or below,
System.out.println("Invalid Input"); // Print that it's invalid
} else if( isTriangle ( a, b, c) ) { // If the method returns true,
System.out.println("Yes, It's a Triangle"); // Print out that it's a triangle
String type = GetType(a, b, c); // Set a variable as a String for an expected string output through the method
System.out.println("Triangle type: " + type); // Print out the type
System.out.println("AREA: " + GetArea(a, b, c)); // Print out the area
} else { // If the method returns false,
System.out.println("Not a Triangle"); // Print that it's not a triangle
}
}
//****************************************************
public static boolean isTriangle(int a , int b, int c ) { // Calculates whether the inputs are equal to the qualities of a triangle
if (a >= b + c || b >= a + c || c >= a + b) { // If any of the bases of the invisible triangle are bigger,
return false; // Return false
} else { // If the two sides are greater or equal to the base,
return true; // Return true
}
} // End of isTriangle
public static String GetType(int a, int b, int c) { // Gets the triangles type (returns a string)
if (a == b && b == c && a == c) { // If the triangle has all equal sides
return "Equilateral";
} else if (a == b || b == c || a == c) { // If most sides are equal with one greater or less than the others
return "Isosceles";
// If the triangle can use 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 { // If it's none of the calculations above,
return "Scalene"; // It must be scalene, always scalene
}
} // End of GetType
public static double GetArea(int a, int b, int c) { // Calculates the invisible triangle's area
double semi = (a + b + c) / 2.0; // Calculates the triangle's semiperimeter
return Math.sqrt(semi * (semi - a) * (semi - b) * (semi - c)); // Returns with the area
} // End of GetArea
} // End of main
To embed this project on your website, copy the following code and paste it into your website's HTML: