The post Relational Operators in Java appeared first on OctopusCodes.
]]>| Operator | Description |
| == | Is Equal To |
| != | Not Equal To |
| > | Greater Than |
| >= | Greater Than or Equal To |
| < | Less Than |
| <= | Less Than or Equal To |
This operator is used to check whether the two given operands are equal or not. The operator returns true if the operand at the left-hand side is equal to the right-hand side, else false.
package octopuscodes.com.demo;
public class Demo {
public static void main(String[] args) {
int a = 10, b = 5;
boolean result1 = a == b;
System.out.println("result 1: " + result1);
int c = 7, d = 7;
boolean result2 = c == d;
System.out.println("result 2: " + result2);
}
}
result 1: false
result 2: true
This operator is used to check whether the two given operands are equal or not. It returns true if the operand at the left-hand side is not equal to the right-hand side, else false.
package octopuscodes.com.demo;
public class Demo {
public static void main(String[] args) {
int a = 10, b = 5;
boolean result1 = a != b;
System.out.println("result 1: " + result1);
int c = 7, d = 7;
boolean result2 = c != d;
System.out.println("result 2: " + result2);
}
}
result 1: true
result 2: false
This checks whether the first operand is greater than the second operand or not. The operator returns true when the operand at the left-hand side is greater than the right-hand side.
package octopuscodes.com.demo;
public class Demo {
public static void main(String[] args) {
int a = 10, b = 5;
boolean result1 = a > b;
System.out.println("result 1: " + result1);
int c = 7, d = 17;
boolean result2 = c > d;
System.out.println("result 2: " + result2);
}
}
result 1: true
result 2: false
This checks whether the first operand is greater than or equal to the second operand or not. The operator returns true when the operand at the left-hand side is greater than or equal to the right-hand side.
package octopuscodes.com.demo;
public class Demo {
public static void main(String[] args) {
int a = 10, b = 5;
boolean result1 = a >= b;
System.out.println("result 1: " + result1);
int c = 7, d = 7;
boolean result2 = c >= d;
System.out.println("result 2: " + result2);
int e = 7, f = 14;
boolean result3 = e >= f;
System.out.println("result 3: " + result3);
}
}
result 1: true
result 2: true
result 3: false
This checks whether the first operand is less than the second operand or not. The operator returns true when the operand at the left-hand side is less than the right-hand side.
package octopuscodes.com.demo;
public class Demo {
public static void main(String[] args) {
int a = 10, b = 5;
boolean result1 = a < b;
System.out.println("result 1: " + result1);
int c = 7, d = 17;
boolean result2 = c < d;
System.out.println("result 2: " + result2);
}
}
result 1: false
result 2: true
This checks whether the first operand is greater than or equal to the second operand or not. The operator returns true when the operand at the left-hand side is greater than or equal to the right-hand side.
package octopuscodes.com.demo;
public class Demo {
public static void main(String[] args) {
int a = 10, b = 5;
boolean result1 = a <= b;
System.out.println("result 1: " + result1);
int c = 7, d = 7;
boolean result2 = c <= d;
System.out.println("result 2: " + result2);
int e = 2, f = 7;
boolean result3 = e <= f;
System.out.println("result 3: " + result3);
}
}
result 1: false
result 2: true
result 3: true
The post Relational Operators in Java appeared first on OctopusCodes.
]]>