Simple Pattern in Java-1

//Java Program displaying a simple pattern

Pattern1.java

Any kind of patterns can be made in a programming language using for loops.

Here in this program the outer for loop determines the no of rows that we want for the pattern and the inner loop represents the no of columns per row.

We created a pattern which ranges only for five rows.

The pattern we want to generate is

*

**

***

****

*****


public class Pattern1
{
	 public static void main(String args[])
	 {

		 for(int i=1; i<=5; i++)//loop for rows
		 {
			for(int j=1; j<=i; j++)//loop for columns
			 {
				 System.out.print("*");
			 }//inner for
			 System.out.println();

		 }//outer for

	 }
}

Snapshot of the o/p

Advertisements

4 thoughts on “Simple Pattern in Java-1

  1. Hi, thanks a lot for this but there are 4 errors coming for me whilst executing. It says “variable i not found” what do I do?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s