Java Relational Operators
Java Relational Operators.
The equality and relational operators determine if one operand is greater than, less than, equal to, or not equal to another operand.Relational Operators:
Name Operator Sample Evaluates
Equals == 100 == 50; false
50 == 50; true
Not equals != 100 != 50; true
50 != 50; false
Greater than > 100 > 50; true
50 > 50; false
Greater than or equal to >= 100 >= 50; true
50 >= 50; true
Less than < 100 < 50; false
50 < 50; false
Less than or equal to <= 100 <= 50; false
50 <= 50; true
Here is a runnable example:
public class Javarelational {
public static void main(String[] args) {
int x = 20, y = 25, z = 25;
System.out.println("Relational Operators");
System.out.println(" y == z = " + (y == z));
System.out.println(" y != x = " + (y == x));
System.out.println(" z > y = " + (z > y));
System.out.println(" y >= x = " + (y >= x));
System.out.println(" x < y = " + (x < y));
System.out.println(" y <= x = " + (y <= x));
}
}
The result of this is:
Relational Operators
y == z = true
y != x = false
z > y = false
y >= x = true
x < y = true
y <= x = false
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.