Star Pattern 4 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<=i;j++)//This inner loop is for the columns { System.out.print("*"); } System.out.println(); } } }
Discussion
In this program, we will print the “*”, a number of times the current value of i.
Here, for the outer loop, I have taken the maximum value for i =5. Now, whenever the inner loop activates for a particular value of i, the value of “i” will become the ceiling value for j, thus it will print the “*” only till the current value of i.
*
**
***
****
*****