• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bingo Card  RSS feed

 
Konrad Cetes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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.




 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!