Equality Operators


#1

https://www.codecademy.com/courses/learn-java/lessons/introduction-to-java/exercises/equality-operators?action=lesson_resume

EqualityOperators.java:6: error: incomparable types: boolean and char
System.out.println(myFact == myChar);

Why isn’t this code working? Apparently in the print statement I can only set a character and an integer data type equal to each other, this code with boolean and char data type won’t work or boolean and int doesn’t work as well can someone explain to me why?


public class EqualityOperators {
	public static void main(String[] args) {

    boolean myFact = false;
    char myChar = 'A';
		System.out.println(myFact == myChar);
    

	}
}



#2

Use any equality operator to directly compare two Boolean values.

Java is very type oriented. Do not expect the type coercion that we have grown used to with JavaScript.

myChar is not ‘truthy’ or ‘falsy’, but, ‘incomparable’.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.