Let’s print some patterns (using loops)

You can use loops, specially “for” loop to print out different patterns. You will see below how to print something in a row and go to next row when the loop is over. Also how to print a space when you need and looping inside a loop to count the number of rows you need to print and so on.

Pattern 1

**********

**********

**********

**********

**********

Here is the code to print out this.

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

for(int y = 1;y <= 10; y++){

System.out.print(“*”);

}

System.out.println(“”);

}

Here is the NetBeans coding with the output.

1

Pattern 2

*****

****

***

**

*

Here is the coding segment for that.

2

Pattern 3

*

***

*****

*******

*********

Here we go with the code.

4

Pattern 4

*****  *****

****       ****

***            ***

**                 **

*                      *

5

Be await… A lot more to come…

Thank you.

 

 

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