Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: issue when comparing 3 positive integers

I've been looking for help on this for few hours now and can't find anything or maybe I'm just not looking in the right places.

I'm trying to create a simple program in Java wich takes three positve integers as command-line-argument and prints TRUE if any one of them is greater or equal to the sum of the other two and FALSE otherwise.

public class Triangle {

    public static void main(String[] args){
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int c = Integer.parseInt(args[2]);
        boolean isTriangle;

        isTriangle = (a + b >= c);
        isTriangle = (b + c >= a);
        isTriangle = (a + c >= b);
        System.out.println(isTriangle);
    }

}

Hope some of could maybe give me an answer or something that points me in the right direction so I can get this right.

like image 682
bangalo Avatar asked Jul 12 '26 06:07

bangalo


1 Answers

public class Triangle {

    public static void main(String[] args){
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int c = Integer.parseInt(args[2]);
        boolean isTriangle;

        isTriangle = (a + b >= c) || (b + c >= a) || (a + c >= b);
        System.out.println(isTriangle);
    }

}
like image 64
Avi Cohen Avatar answered Jul 14 '26 19:07

Avi Cohen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!