Star Pattern 1 in Java
class Pattern { public static void main(String args[]) { for(int i = 1;i <= 5;i++)//This outer loop is for the rows { for(int j =1;j<=5;j++)//This inner loop is for the columns { System.out.print("*"); } System.out.println(); } } }
Discussion
Here we have taken two for loops in which the outer loop describes the rows required while the inner loops describe the columns.
Now as the value of i=1,the number of columns will be printed is 5,
*****
And now, we have to print all the 5 rows consecutively, so the value of i will be incremented by 1 (i++) and the value will be again raised to 2, then the second line will be printed.
In a similar fashion, all the lines will be printed one by one and the final result will look like…
*****
*****
*****
*****
*****