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

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