Thursday, October 25, 2012

Use "FOR" Loop to create "Arrow" !!!

Hello guys, you can use for loop to create different design. In this post I am going to create following design.


*
***
*****
*******
*********
***********
***********
*********
*******
*****
***
*
_______________________________________________________________

What do you think, how can we do this????

Lets see the following code....................





public class Loop {

public static void main(String[] args){


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

for(int y=0; y<=x*2; y++){

System.out.print("*");
}


System.out.println("");


}

for(int x=5; x>=0; x--){

for(int y=0; y<=x*2; y++){

System.out.print("*");



}


System.out.println("");

                 
                }

}

}


_________________________________________________________________

Try to do some experiment with this code and you can create something else,


You can replace "*" with any other symbol you like. And also try to do debug of this program to understand it step by step.


Just Do It...................

cheers.................

No comments:

Post a Comment