Java Boolean compare() method

The compare() method of Java Boolean class compares the two Boolean values (x and y) and returns an integer value based on the result of this method.

Syntax:

Parameters:

Here, x(first boolean) and y( second boolean) are two boolean parameters passed which are compared.

Return Value:

This method returns an integer value.

  • It returns value 0, if x==y.
  • It returns positive value, if x is true and y is false.
  • It returns a negative value, if x is false and y is true.

Example 1

Test it Now

Output:

b1 value is true

Example 2

Output:

Enter two no.s
I no :89
II no :98
98 is greater

Example 3

Output:

Enter your percentage: 74.9999
Sorry! Your percentage is lower than our requirement. 

Next TopicJava Boolean




Latest Courses