The inequality operator != has the following form
operand1 != operand2
The inequality operator returns true if operand1 and operand2 are not equal. Otherwise, it returns false.
The following code shows how to use Inequality Operator.
int i = 1; int j = 2; int k = 3; boolean b; b = (i != j); // Assigns true to b b = (i != k); // Assigns false to b b = (true != true); // Assigns false to b b = (true != false); // Assigns true to b b = (false != true); // Assigns true to b
public class Main { public static void main(String[] args) { int i = 1; /* ww w .ja va2s. c o m*/ int j = 2; int k = 3; boolean b; b = (i != j); // Assigns true to b System.out.println(b); b = (i != k); // Assigns false to b System.out.println(b); b = (true != true); // Assigns false to b System.out.println(b); b = (true != false); // Assigns true to b System.out.println(b); b = (false != true); // Assigns true to b System.out.println(b); } }