by Dinesh Thakur

In this example we reviewed six comparison operator <, <=,>,> =, == And ! =. Comparison operators always produce a boolean result value (true or false). Java has several comparison operator, which can be used for the comparison of any combination of integers, with float or symbols.

Operator

Action

==

equal

! =

Not

> 

Greater

> =

Greater than or equal

< 

Less

<=

Less than or equal

 

In this sample Comparison Operators Example, first created two variables a and b and their appropriated values ​​100 and 50 . The next line printed on the console rules by the method println () to System.out, the result of the comparison of the two variables a and b by the operator > . The returned result is true, because a has a larger value of b. On the next 50 order prints the returned result from the use of the remaining 50 comparison operator with variables a and b.

Here's a sample program that demonstrates the use of operators for comparison in Java:

public class ComparisonOperators 

{

     public static void main(String args[])

    {

          int a = 100, b = 50;

          System.out.println("a > b : " + (a > b)); // true

          System.out.println("a < b : " + (a < b)); // false

          System.out.println("a >= b : " + (a >= b)); // true

          System.out.println("a <= b : " + (a <= b)); // false

          System.out.println("a == b : " + (a == b)); // false

          System.out.println("a != b : " + (a != b)); // true

    }

}