I have been asked
Given the definitions of a, b and c below, select the expressions that compile successfully and evaluate to true.
int a = 1; char b = 'a'; boolean c = false;
So I used a simple
if (expression)
{System.out.println("True");}
else
{System.out.println("False");}
Is this right?
c==a //false
!c || a //false
b >= a //true
c = a //false
a - b - 96 //false
a + b > 0 //true
c = true //true
a < b //true
Does this look ok?
c==a: doesn’t compile,intcan’t be compared toboolean.!c || a: doesn’t compile,boolean || intisn’t allowedb >= a: compiles, evaluates totruec = a: doesn’t compile, can’t assign anintvalue to abooleana - b - 96: compiles, evaluates to -192a + b > 0: compiles, evaluates totruec = true: compiles, evaluates totrue(and assignstruetoc)a < b: compiles, evaluates totrue