Friday, February 9, 2018

Print triangle pattern



class Pattern {
public static void main (String [ ] arg) {

int i, j ;

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

for ( j=1; j<=9; j++) {

if ( j>=6-i & & j<=4+i )
{
System.out.println (" * ") ;
}
else
{

System.out.println ("  ") ;
}
}
System.out.println (" ") ;
}
}
}

output:-             *
                         ***
                       *****
                     *******
                   *********

0 comments:

Post a Comment