Skip to content

Commit f84589c

Browse files
authored
Create Triangle.java
1 parent 7145881 commit f84589c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Triangle.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//*******************************************************
2+
// Triangle.java
3+
// Checking whether three numbers form the length of a triangle
4+
//*******************************************************
5+
import java.util.Scanner;
6+
public class Triangle
7+
{
8+
public static void main (String [] args)
9+
{
10+
Scanner scan = new Scanner (System.in); // Create Reader
11+
System.out.println("This program Checking whether three numbers form the length of a triangle.");
12+
System.out.print("Enter three numbers"); // Ask for input
13+
int x = scan.nextInt(); // Read value from user
14+
int y = scan.nextInt();
15+
int z = scan.nextInt();
16+
17+
// Checking the correctnees of the input
18+
if( x <= 0 || y <= 0 || z <= 0)
19+
{
20+
System.out.println("The numbers: " + x + ", " + y + " and " + z + " cannot represent a triangle");
21+
}
22+
// checking if the numbers form triangle
23+
else if (x + y > z && x + z > y && y + z > x)
24+
{
25+
// checking if the triangle is Equilateral triangle
26+
if (x==y && x==z)
27+
{
28+
System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an equilateral triangle");
29+
}
30+
// Checking if the triangle is isosceles triangle
31+
else if((x==y) || (x==z) || (y==z))
32+
{
33+
System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an isosceles triangle");
34+
}
35+
// Checking if the triangle is right-angle triangle
36+
else if ( (x*x + y*y == z*z) || (y*y + z*z == x*x) || (x*x + z*z == y*y))
37+
{
38+
System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an right-angle triangle");
39+
}
40+
else
41+
{
42+
System.out.print("The numbers: " + x + ", " + y + " and " + z + " represent an common triangle");
43+
}
44+
}
45+
else
46+
{
47+
System.out.print("The numbers: " + x + ", " + y + " and " + z + " cannot represent a triangle");
48+
}
49+
}// end of method main
50+
}// end of class Triangle

0 commit comments

Comments
 (0)