June 2018
Beginner
722 pages
18h 47m
English
Relational operators can only be used with primitive types:
int i1 = 1;int i2 = 2;int i3 = 1;System.out.println(i1 > i2); //prints: falseSystem.out.println(i1 >= i2); //prints: falseSystem.out.println(i1 >= i3); //prints: trueSystem.out.println(i1 < i2); //prints: trueSystem.out.println(i1 <= i2); //prints: trueSystem.out.println(i1 <= i3); //prints: trueSystem.out.println('a' >= 'b'); //prints: falseSystem.out.println('a' <= 'b'); //prints: truedouble d1 = 1/3;double d2 = 0.34;double d3 = 0.33;System.out.println(d1 < d2); //prints: trueSystem.out.println(d1 >= d3); //prints: false
In the preceding code, we see that int type values compare to each other as expected, and char type values compare to each ...
Read now
Unlock full access