< Prev
Next >

Relational Operators

This operator is also knows an not equal to operator. It compares between the values of its two operands by checking for their inequality. It returns a boolean value true when operands have unequal values otherwise it returns false.

A coding example with != operator

// Java - Example of != relational operator

class A
public static void main(String... ar)
if('z' != 'a') 		//comparing a character to another character
System.out.println("z is not equal to a");

if(100 != 100.001)	//comparing an int with a double
System.out.println("100 is not equal to 100.001");

if(99.9999 != 99.999)	//comparing a double with a double
System.out.println("99.9999 is  not equal to 99.999");

if(5.00 != 5.0)		//comparing an int to double
System.out.println("5.00 is not equal to 5.0");

if(11 !=10)
System.out.println("11 is not equal to 10");

if(98 != 'a')		//comparing int to ASCII value of a character
System.out.println("98 is not equal to a");


Output -

z is not equal to a
100 is not equal to 100.001
99.9999 is  not equal to 99.999
11 is equal to 10
98 is equal to a
Note : There should never be any space between ! and = of != operator, or a compile error is thrown.

Please share this article -

< Prev
Next >
< Compound Assignment Operators
Logical Operators>


Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition