Java Greater Than or Equal To
In Java, Greater Than or Equal To Relational Operator is used to check if first operand is greater than or equal to the second operand. In this tutorial, we will learn how to use the Greater Than or Equal To Operator in Java, with examples.
The symbols used for Greater Than or Equal To operator is >=
. Greater Than or Equal To operator takes two operands: left operand and right operand as shown in the following.
left_operand >= right_operand
The syntax to check if x
is greater than or equal to y
using Greater Than or Equal To operator is
x >= y
The operator returns a boolean value of true
if x
is greater than or equal to y
, or false
if not.
The following table gives the return value of Less Than or Equal to operator for some operand values.
x | y | x >= y |
---|---|---|
4 | 8 | false |
4 | 4 | true |
9 | 2 | true |
Examples
In the following example, we take two integer values in x
and y
, and check if the value in x
is greater than or equal to y
, using Greater Than or Equal To operator.
Main.java
public class Main {
public static void main(String[] args) {
int x = 8;
int y = 4;
if (x >= y) {
System.out.println("x is greater than or equal to y.");
} else {
System.out.println("x is not greater than or equal to y.");
}
}
}
Output
x is greater than or equal to y.
Since value in x
is greater than that of in y
, x >= y
returned true.
Now, let us take values in x
and y
such that x
is not greater than or equal to y
, and observe what Greater Than or Equal To operator returns for these operand values.
Main.java
public class Main {
public static void main(String[] args) {
int x = 8;
int y = 9;
if (x >= y) {
System.out.println("x is greater than or equal to y.");
} else {
System.out.println("x is not greater than or equal to y.");
}
}
}
Output
x is not greater than or equal to y.
Since value in x
is not greater than or equal to that of in y
, x >= y
returned false.
Conclusion
In this Java Tutorial, we learned what Greater Than or Equal To operator is, its syntax and usage in Java Programs with the help of examples.