Titanic Lover Titanic Lover - 9 months ago 57
Java Question

Stuck in Indenting spaces according to numbers using a nested loop

I need some help. I want my program to print different numbers according to the user's input and indent that number with that number of spaces as well. Must be using a nested loop.

Expected Output: (lets say user types



for simplicity I'm only showing you what I did in the nested for loop and ignoring the user's input portion.

What I did:

for (i=0; i<=userNum; i++)
for (j=0; j<=i; j++)
? (I think here is the problem as I don't know how to indent by that no of spaces)

Thanks in advance!

Answer Source

Inside the loop you should use

System.out.print(" ");