-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompareTriangleSides.java
53 lines (39 loc) · 1.21 KB
/
CompareTriangleSides.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class CompareTriangleSides {
public static String compareTriangleSides( float sides[] ) {
int sideArraySize = sides.length;
int countEqualSides = 0;
int j = 1;
for ( int i = 0; i < sideArraySize; i++ ) {
if ( j == sideArraySize ) { j = 0; }
if ( sides[ i ] == sides[ j ] && countEqualSides != 2 ) {
countEqualSides++;
}
j++;
}
String triangleType = "";
switch ( countEqualSides ) {
case 0:
triangleType = "scalene";
break;
case 1:
triangleType = "isosceles";
break;
case 2:
triangleType = "equilateral";
break;
}
return triangleType;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println( "TRIANGLE TYPE:\n" );
System.out.println( "Type the lengths of the sides of the triangle" );
float sides[] = new float[ 3 ];
for ( int i = 0; i < 3; i++ ) {
System.out.println( "Side " + i + ": " ); sides[i] = input.nextFloat();
}
String triangleType = compareTriangleSides( sides );
System.out.println( "According to the given dimensions, the triangle is " + triangleType );
}
}