• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printf

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic