Simple Numeric Pattern in Java-2

//Java Program displaying a simple numeric pattern

Pattern2.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.

Like the previous example here we replace the “*” by j(the variable value gets displayed)

So we get a numeric pattern

1

12

123

1234

12345



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

		 for(int i=1; i<=5; i++){

			 for(int j=1; j<=i; j++){
				 System.out.print(j);
			 }//inner for
			 System.out.println();

		 }//outer for

	 }
}

Snapshot of the o/p

Advertisements

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