Class Output { Public static void main ( String args[]) { String str= "true false true"; boolean x= Boolean.valueOf(str); System.out.print(x); } } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Class Output { Public static void main ( String args[]) { String str= "true false true"; boolean x= Boolean.valueOf(str); System.out.print(x); } }

What is the output of this program..?

25th Feb 2017, 9:09 PM
bhargav
5 Answers
+ 5
false - because str doesn't contain a boolean value. It will always output false, except for str="true";
25th Feb 2017, 9:17 PM
Tashi N
Tashi N - avatar
+ 5
Ok ^^ This is a typecast from String to Boolean. TheĀ BooleanĀ to which was casted is true if the string is notĀ nullĀ and is equal to the string "true" (ignoring case, so e.g "TRUE" or "tRue" is also true). Every other value stored to the string will be a Boolean representing false value after typecast.
25th Feb 2017, 9:41 PM
Tashi N
Tashi N - avatar
+ 1
Okay..thank you for your time..
25th Feb 2017, 9:50 PM
bhargav
0
Can u explain little bit more..?
25th Feb 2017, 9:32 PM
bhargav
0
boolean and strings are two different types of variables. the program you gave as an example makes as much sence as "what does the number red smell like?"
26th Feb 2017, 4:27 AM
oddeofreq
oddeofreq - avatar