Question #3903

Write a program called TriangleChecker that has the following specification:

a. Accept three command line arguments that can give integer data values. These arguments represent the lengths if the sides of a triangle.

b.Check whether the 3 values can be the sides of a triangle. A triangle will not be possible if the sum of any two is less than or equal to the third.

Expert's answer

import java.util.*;public class TriangleChecker {
public static boolean check(int a, int b, int c) {
if (((a + b) <= c) || ((a + c) <= b) || ((c + b) <= a))
return false;
else
return true;
}

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int side_a;
int side_b;
int side_c;
System.out.println("Enter side a");
side_a = scan.nextInt();
System.out.println("Enter side b");
side_b = scan.nextInt();
System.out.println("Enter side c");
side_c = scan.nextInt();
System.out.println(check(side_a, side_b, side_c));

}
}
LATEST TUTORIALS
APPROVED BY CLIENTS