Relational Operators in Java
Relational Operators are a bunch of binary operators that are used to check for relations between two operands including equality, greater than, less than, etc. They return a boolean result after the comparison and are extensively used in looping statements as well as conditional if-else statements and so on.Relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.
| Operator | Uses |
|---|---|
| == | equality operator |
| != | non-equality operator |
| < | less than operator |
| > | greater than operator |
| <= | less than or equal to operator |
| >= | greater than or equal to operator |
Code Snippet
//Relational Operators in Java
public class App {
public static void main(String[] args) {
int a = 100, b = 50;
System.out.println("Equal to : " + (a == b));
System.out.println("Not Equal to : " + (a != b));
System.out.println("Greater than : " + (a > b));
System.out.println("Less than : " + (a < b));
System.out.println("Greater than or equal to : " + (a >= b));
System.out.println("Less than or equal to : " + (a <= b));
}
}