We have to print a diagonal in this problem.
Let's analyze the required output format.
We realize that the star has to be printed on a row has to be printed on the same column number.
We recognize this design structure and try to use it for our loop formation. This information tells us that when the value of our outer loop iterator ("i" for instance) and inner loop iterator("j" for instance) are same, we will be at the desired location on the console output to print star. This will give us our desired diagonal.
But first, let's understand the programming procedure to reach this step.
This program will print us a square of "n" stars.
But we know we have to print the star only when value of i = value of j; and leave a space (tab) rest of the times.
Making adjustments in the code to accommodate the same: