I want to count from 1 to 10 with a variable width.
Example for width: 4
Count Should Be:
0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 ---> Note that it's not 00010
Example for width: 2
Count Should Be:
01 ... 09 10 ---> Not 010
I've tried the following:
First attempt
for(int i = 1; i <= 10; ++i) {
System.out.println("0".repeat(width-1) + i);
}
Second attempt
String output = String.format("%04d", 1);
These do not properly format numbers as the number of digits changes.