Various type of operator in java
There Five types of relational operators in java
No | Operator | USD | Description |
---|---|---|---|
1 | == | A == C | Double Equal to |
2 | != | A!=B | Not equal to |
3 | > | A>B | Greater than |
4 | < | c<A | Less than |
5 | >= | A>=B | Greater than or equal to |
6 | <= | A<=B | Less than or equal to |
1) Double Equal
- Check the value of two operands is equal or not if a condition is satisfied then true otherwise false
Example
public class DoubleEqualoperator {
public static void main(String[] args) {
int a = 10;
int b = 10;
int c = 20;
//check the value of a and b
System.out.println(a==b);
//check the value of a and c
System.out.println(a==c);
}
}
output
true
false
2) Not equal
- check the value of two operands is equal or not if a condition is satisfied then the true otherwise false
Example
public class NotEqualOperator {
public static void main(String[] args) {
int n1 = 34;
int n2 = 17;
int n3 = 17;
//check the va;ue of n1 and n2
System.out.println(n1 != n2);
//check the value of n2 and n3
System.out.println(n2 != n3);
}
}
output
true
false
3) Greater than
- check the value of the left operand is greater than the value of right operand if a condition is satisfied than true otherwise false
Example
public class GreaterThanoperator {
public static void main(String[] args) {
int a1 = 25;
int a2 = 45;
int a3 = 20;
//check the value of a1 and a2
System.out.println(a1>a2);
//check the value of a3 and a1
System.out.println(a1>a3);
}
}
output
false
true
4) Less than
Example
public class LessThanOperator {
public static void main(String[] args) {
int n1= 34;
int n2 = 56;
int n3 = 89;
//chekc the value of n1 and n2
System.out.println(n1
output
true
false
5) Greater Than Or Equal To
- This operator is a combination of two operators greate than and equal
- check the value of the left operand is greater than or equal to the value of right operand if a condition is satisfied then true otherwise false
Example
public class GreaterThanorEquals {
public static void main(String[] args) {
int a1= 34;
int a2 = 56;
int a3 = 34;
//check the value of a1 and a2
System.out.println(a1 >= a2);
System.out.println(a2 >= a1);
//chekc the value of a1 and a3
System.out.println(a1 >= a3);
}
}
Output
false
true
true
6) Less Than or Equal To
- in this operator in two operators less than and equal
- check the value of the left operand is less than or equal to the right operand value if a condition is satisfied than true otherwise false
Example
public class LessThanOrEqualto {
public static void main(String[] args) {
int c1 = 24;
int c2 = 340;
int c3 = 24;
//value of c1 and c2
System.out.println(c1 <= c2);
System.out.println(c2 <= c1);
//value of c1 and c3
System.out.println(c1 <= c3);
}
}
Output
true
false
true
Tags:
operator