Explain the following operator with an example program: Relational Operator
Advertisements
Question
Explain the following operator with an example program:
Relational Operator
Code Writing
Explain
Advertisements
Solution
A Relational Operator in Java is used to compare two values or expressions. It determines the relationship between them and returns a Boolean value, either true or false.
The relational operators in Java are greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), equal to (==) and not equal to (!=).
Example:
class RelationalOperator
{
public static void main(String[] args)
{
int a = 10, 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
true
false
true
false
true
shaalaa.com
Is there an error in this question or solution?
