need some explanation of how "!=" works, I took this from past exam paper, in theory ( a==b || a==c || b!=c ) should work but when you compile it says "Scalene" instead of "Isosceles", it doesn't work until I change it to (!( a==b || a==c) || b!=c )).
class test { public static void main(String[] args) { int a = 5; int b = 5; int c = 10; if ( a > 0 & b > 0 & c > 0) { if (a==b && b==c) { System.out.println("Equilateral"); } else if ( a==b || a==c || b!=c ) { System.out.println("Scalene"); } else if ( a+b>c && a+c>b || b+c>a ) { System.out.println("Isosceles"); } } } }
short-circuit.a==b ||istrue, the rest is not important(!( a==b || a==c) || b!=c ))is incorrect for testing if the triangle is scalene; if you switch the values ofaandcthat still tells you that the triangle is scalene when it isn't.