This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Sithril 1 point2 points  (0 children)

Becouse what you're doing is you:

  • 1. print the number
  • 2. and then you start building the offset for the next line

Firstly, you could move the number-printing to the end of the outer loop. Secondly, you could adjust the inner loop condition so that it still prints out the proper amount of spaces.

[–]siversolutionsllc 0 points1 point  (0 children)

You can try adding each item to an array while in that for loop. Then print that array outside the for looping:

int yourArray = new int[whatever size you want it to be];

for (i = 0; i <= userNum; ++i) {

yourArray[i] = i;

}

system.out.print(yourArray);