• 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

Bingo Card

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've created a Bingo card, however the columns are not aligned with each other. I am trying to add a zero in front of any number that is less than 10 in hopes that it will fix the problem.




 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do it with System.out.printf().  It's a little obscure, but I'll walk you through it.

System.out.printf(<format_string>, arg1 [, arg2 ...]);

The format string has "markers" in it that tell where to place the arguments.  The markers start with a "%", then a conversion character.  "d" is for digit, "f" is for floating point, and "s" is for string.  There are others, but those will get you far.

In between the "%" and the conversion character can go flags, width, and a precision.  We need a flag of "0" to signify zero-filled and a width of 2.  Pulling it all together, we have:

System.out.printf("%02d | ", digit);

Fiddle around with it a see how that works.  To read more about the format, click here.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic