Explain the Relation Operator with the help of an example program.
Advertisements
प्रश्न
Explain the Relation Operator with the help of an example program.
स्पष्ट करा
Advertisements
उत्तर
In Java, Relational Operators are used to compare two values or expressions. These operators determine the relationship between two operands and return a Boolean value, either true or false, depending on the result of the comparison.
The various relational operators in Java are:
|
Operator |
Description |
|---|---|
|
|
Greater than |
|
|
Less than |
|
|
Greater than or equal to |
|
|
Less than or equal to |
|
|
Equal to |
|
|
Not equal to |
Example Program:
class RelationalOperator
{
public static void main(String[] args)
{
int a = 10;
int b = 20;
System.out.println(a > b);
System.out.println(a < b);
System.out.println(a >= b);
System.out.println(a <= b);
System.out.println(a == b);
System.out.println(a != b);
}
}
Output:
false
true
false
true
false
true
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
