Try this instead:
for (int i = 0; i < n; i++)
System.out.print(i % 7 + 1 + " ");
Whenever you want to have that "repeating" behavior, where a sequence of numbers goes up to a certain value and then restarts, use the %
operator and a bit of modular arithmetic to achieve the desired effect. For n = 17
the above will print:
1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3