Thursday, July 18, 2013

Program using for loop

HELLO FRIENDS NOW LET WE WRITE PROGRAM TO PRINT THE BELOW PATTERN

*****
****
***
**
*
*
**
***
****
*****

PROGRAM:
~~~~~~~

public class JavaPattern {

public static void main(String[] args) {

//generate upper half of the pattern
for(int i=5; i>0 ;i--)//takes care on printing row values
{

for(int j=0; j < i; j++)//takes care on printing columns values
{
System.out.print("*");
}

//create a new line
System.out.println("");
}

//generate bottom half of the pattern
for(int i=1; i<= 5 ;i++)
{

for(int j=0; j < i; j++)
{
System.out.print("*");
}

//create a new line
System.out.println("");
}

}
}

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips