Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printf

 
Srinivas Katta
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain the below , I have gone through printf specifications but the below statement is confusing for me



Thanks
Srinivas
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem you have is with the "true" part which is get printed.When you try to convert something in to boolean if it is false it returns false .Any other occurrences returns true value .So here second argument 654 is convert to a boolean value and returns a true .I suggest you to read the printf and Formatter API . And K&B have good examples on these matters.
 
Srinivas Katta
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Clarification, But I have the similar code using teh formatter class as given below


it prints the output as true false but I am expecting it to be false false
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the exact thing I explained earlier .You can pass a string value to Boolean constructor and it doesn't check for Case sensitiveness. Whether you pass TRuE TRUE or true it makes a boolean Wrapper object of true value.

printf only returns false if you convert a boolean false value to a boolean.Here what you pass is a String object ("FAlse").Whether you change it to "false" it still returns true, until you pass a boolean false value .

check this code
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic