Relational operators in JAVA are the binary operator, as we know know binary operator take two parameter .For comparing values of variables ad literals Java provided relational operators. Relational operators relate a given value with several possible values of a variable . The result of the relational operators help to make branching iterating a block and to terminate the block statement
Relational operator returns boolean i.e true or false
== equal to
!= not equal to
> greater than
>= greater than equal to
< less than
<= less than equal to
for instance/example
int a = 25;
int b=75;
double x=35.87;
double x=85.87;
char c1='b';
char c2='c';
..............................................
a=b false
a!=b true
a<b true
x>y false
c1==c2 false
35==10 false
...............................................
Example :
class RelationalOperatorDemo{public static void main(String[] args){int firstVar = 2;int secondVar= 9;if(firstVar == secondVar)System.out.println("firstVar == secondVar");if(firstVar != secondVar)System.out.println("firstVar != secondVar");if(firstVar > secondVar)System.out.println("firstVar > secondVar");if(firstVar < secondVar)System.out.println("firstVar < secondVar");if(firstVar <= secondVar)System.out.println("firstVar <= secondVar");}}
The Output will be
firstVar != secondVarfirstVar < secondVarfirstVar <= secondVar
hi
ReplyDeletehello any query related to java
ReplyDelete