Java program to check the constructing criteria of a triangle.



Triangle

From Wikipedia, the free encyclopedia


A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in geometry. A triangle with vertices A, B, and C is denoted .

In Euclidean geometry, any three points, when non-collinear, determine a unique triangle and simultaneously, a unique plane (i.e. a two-dimensional Euclidean space). In other words, there is only one plane that contains that triangle, and every triangle is contained in some plane. If the entire geometry is only the Euclidean plane, there is only one plane and all triangles are contained in it; however, in higher-dimensional Euclidean spaces, this is no longer true. This article is about triangles in Euclidean geometry, and in particular, the Euclidean plane, except where otherwise noted.

Existence of a triangle

Condition on the sides

The triangle inequality states that the sum of the lengths of any two sides of a triangle must be greater than or equal to the length of the third side. That sum can equal the length of the third side only in the case of a degenerate triangle, one with collinear vertices. It is not possible for that sum to be less than the length of the third side. A triangle with three given positive side lengths exists if and only if those side lengths satisfy the triangle inequality.


Conditions on the angles

Three given angles form a non-degenerate triangle (and indeed an infinitude of them) if and only if both of these conditions hold: (a) each of the angles is positive, and (b) the sum of the angles to 180°. If degenerate triangles are permitted, angles of 0° are permitted.




the code for this problem is:

import java.util.Scanner;
public class possibleTriangles {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter length of first side of the triangle: ");
double a = scanner.nextDouble();
System.out.println("Enter length of second side: ");
double b = scanner.nextDouble();
System.out.println("Enter length of third side: ");
double c = scanner.nextDouble();
if ((a + b > c) && (b + c > a) && (a + c > b)) {
System.out.println("The construction of this triangle is possible: ");
}
else {
System.out.println("The construction of this triangle is not possible: ");
}
}
}







No comments:

Post a Comment