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 |
This is a Java program that demonstrates the use of relational operators to compare two integer variables a and b. The program initializes the variables a and b with the values 100 and 50, respectively. It then uses six different relational operators to compare the values of a and b, and prints the result of each comparison to the console using the System.out.println() method.
public class relational { 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)); } }
Equal to : false Not Equal to : true Greater than : true Less than : false Greater than or equal to : true Less than or equal to : falseTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions