Problem Statement:
Write a program to draw the following pattern of NxN(where N is the input):
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
(here, N=5)
THE CODE
Output:
Here, the input is 8
Simplification:
In the above problem, two for loops are used:
1. The first for loop is having i as counter variable with initial value of 1 and ending value of 10 with an updation statement i++.
2. The second for loop is having j as counter variable with initial value of 1 and ending value of 10 with an updation statement j++.
The second for loop is used to print * in the respective column (the value of j represents the column number). It is having a print statement System.out.println("* ") to print * in each column(for convenience, I've added a space for better visibility of columns in the output).
The first for loop is used to define rows( the value of i represents the row number). It is having a print statement System.out.print() to change rows each time the second for loop completes.
Note:
System.out.println() is used to print on the next line whereas System.out.print() is used to print on the same line.