Alternatively, you can use printf, which is used in C.
When using printf, you use placeholders which you can format. The placeholder for int is %d. If you want to indicate that all numbers should have 2 spaces, you use the placeholder %2d. If you want all numbers to hold 2 spaces and have a leading zero if the space(s) in front of the number would otherwise be just an empty space, you use the placeholder %02d.
So, if you want all of your numbers to be aligned
without leading zeros, your code would look like this:
int number = 0;
for(int i=1; i<11; i++){
number = (int) (Math.random()* 100);
System.out.printf("%2d", number);
}
If you want all of your numbers to be aligned
with leading zeros, your code would look like this:
int number = 0;
for(int i=1; i<11; i++){
number = (int) (Math.random()* 100);
System.out.printf("%02d", number);
}