+ 1

Whats a good example of casting a integer to a boolean value?

I am trying to use the compareTo method; using -1, 0, and 1. I need to cast these into boolean. Not worried about the 0 though.

14th Mar 2019, 2:22 PM
Amber Janosh
Amber Janosh - avatar
1 ответ
+ 3
Assuming 1 will be cast to true and 0 to false, what should -1 be? If you consider any number which is not 0, to be true, and only 0 to be false, the simplest way would be to do (n != 0) This gives you true for 1, true for -1, and false for 0.
14th Mar 2019, 2:24 PM
Hatsy Rei
Hatsy Rei - avatar