Print all 0

Asked

Viewed 58 times

0

I declared the following variable:

int sequencia = 000000000;

At the time of printing, is printing only a 0.

Does anyone know how to print all 0 (zeros) ?

How do I auto-increment to the point that every turn (for) the value changes to: 000000001,000000002 until you reach 999999999 ?

  • You will have to print as string, using printf.

  • You need to declare the variable as string, the int already converts 00000000 for 0.

  • This number will be incremented later, I’ll see how you keep trying to use the parse.

  • Mathematically, 000001 is 1. If you want to print a known amount of characters, you will need to do "zero-padding" until you fill the left side

  • Guys, how do I auto-increment to the point that every turn (for) the value changes to: 000000001,000000002 until you get 999999999 ?

1 answer

3


for (int i = 0; i <= 999999999; i++) {
    System.out.println(String.format("%09d", i));
}

See the example above working on IDEONE

  • Show, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.