Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why does this work with %s

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why does this work with %s if i want to print only 123..is there any other way with &f?
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%b and %s can work with any type of argument.

If you want to print 123 use %.0f
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got the answer.......%s formats an object by calling its toString() method..hence 123.456 is converted into string and printed out......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic