Relational Operators
An Introduction with Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
true
or
false
>
<
==
!=
>=
<=
7 < 5
3 == 3
7 != 7
this_variable < that_variable
this_variable >= 15
(x + y) != (a * b)
byte
short
int
long
float
double
String
)boolean
Operands==
and !=
operators can be used with boolean
operandsboolean
Operands (cont.)x == true
y == false
x == true
and x
evaluate to
exactly the same thing x
evaluates to true
it follows that
x == true
evaluates to true
, and
when x
evaluates to false
it follows
that x == true
evaluates
to false
)
y == false
and !y
evaluate
to exactly the same thing y
evaluates to true
it follows that !y
evaluates to
false
and y == true
evaluates to
false
, and when y
evaluates to
false
it follows that !y
evaluates to
true
and y == false
evaluates to true
)a + 0
instead
of a
and almost all style guides prohibit their
useboolean
value they can be "combined" using logical operators(gpa >= 2.0) && (credits >=120)
Which of the following expressions are syntactically correct?
Which of the following assignment statements are syntactically correct?