Home > Enterprise >  The operator == is undefined for the argument type(s) boolean, int [duplicate]
The operator == is undefined for the argument type(s) boolean, int [duplicate]

Time:09-27

I'm trying to create a pretty simples program in Java and that problem appears "The operator == is undefined for the argument type(s) boolean, int", which is weird because I'm pretty sure that I can use == to compare integers (Int). If anyone could help it would be awesome!

Scanner scanner = new Scanner(System.in);

    int firstSide, secondSide, thirdSide;
    
    System.out.println("Insert the first side lenght of the triangle: ");
    firstSide = scanner.nextInt();
    System.out.println("Insert the second side lenght of the triangle: ");
    secondSide = scanner.nextInt();
    System.out.println("Insert the third side lenght of the triangle: ");
    thirdSide = scanner.nextInt();
    
    
    if (firstSide   secondSide < thirdSide) {
        System.out.println("That triangle doesn't exist! 1");
        return;
    } else if (firstSide   thirdSide < secondSide) {
        System.out.println("That triangle doesn't exist! 2");
        return;
    } else if (secondSide   thirdSide < firstSide) {
        System.out.println("That triangle doesn't exist! 3");
        return;
    } else {
        System.out.println("Everything is OK!");
    }
    
    // Remember that:
    // An Equilateral triangle is a triangle that has all its sides equal.
    // An Isosceles triangle has 2 equal sides.  
    // A Scalene triangle has all different sides.
    
    ******if (firstSide == secondSide == thirdSide) {
        System.out.println("That's an EQUILATERAL triangle!");
    } else if (firstSide == secondSide) {
        System.out.println("That's an ISOSCELES triangle!");
    } else if (thirdSide == firstSide) {
        System.out.println("That's an ISOSCELES triangle!");
    } else if (secondSide == thirdSide) {
        System.out.println("That's an ISOSCELES triangle!");
    } else {
        System.out.println("That's a SCALENE triangle!");
    }

CodePudding user response:

Replace this condition if (firstSide == secondSide == thirdSide)

by if (firstSide == secondSide && firstSide == thirdSide)

firstSide == secondSide : return a boolean value (true or false)

CodePudding user response:

the nextint method could cause problems sometimes as it does not go to the next line. I'd recommend using nextLine instead and pass the int as a String.

  •  Tags:  
  • java
  • Related