+ 17
Why the output is false?
public class Program { public static void main(String[] args) { var b1 = Boolean.valueOf("1"); var b2 = Boolean.valueOf("0"); System.out.print(b1 || b2); } }
7 Antworten
+ 10
bool returns true for 1 and false for the rest. it receives the ascii codes for "0" and "1" and both are different from 1, so both variables are set to false. Tks to notqueued
+ 9
Boolean.valueOf("True") returns Boolean.TRUE.
Boolean.valueOf("TRUE") returns Boolean.TRUE.
Boolean.valueOf("tRuE") returns Boolean.TRUE.
Boolean.valueOf("yes") returns Boolean.FALSE.
Boolean.valueOf("y") returns Boolean.FALSE.
Boolean.valueOf("no") returns Boolean.FALSE.
Boolean.valueOf("false") returns Boolean.FALSE.
Boolean.valueOf("False") returns Boolean.FALSE.
Boolean.valueOf("FALSE") returns Boolean.FALSE.
for true as output compulsary the string argument contain "true" in any case upper,lower,mix ,
+ 6
If the string argument is not the string "true" then it returns false as far as I know. For the Boolean.valueOf(String);
+ 2
🌀Saroj Patel🌀🇮🇳 it s more clear now. Thank you
+ 2
Easy, anything that is not "true" in any case is false.
+ 1
Java boolean values can only equal 'true' or 'false', unlike some other languages ( 1 or 0, etc.) right? Maybe it's as simple as Java defaulting boolean values to 'false'? 🤔
0
Alright. Think of this in terms of boolean algebra. false is 1, true is 0. b1 is false, b2 is true.
false or true = 1 OR 0 = 1 = false
That should give you a good approach to tackle boolean algebra in programming