Pattern Printing using Java






Write a Program in
java to print the following pattern





*


***


*****


*******


*********


*******


*****


***


*




































Program:


class Sk23


 {


  public
static void main(String args[ ])


   {


    int i, j,
k;


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


    {


       
for(j=i;j<5;j++)


             {


           
System.out.print(" ");


             }


       
for(k=1;k<(i*2);k++)


             {


             
System.out.print("*");


             }


       
System.out.println("");


    }


   
for(i=4;i>=1;i--)


    {


       
for(j=5;j>i;j--)


             {


             
System.out.print(" ");


             }


       
for(k=1;k<(i*2);k++)


             {


             
System.out.print("*");


             }


       
System.out.println(" ");


    }





    }


 }


Compile:


D:\>javac
Sk23.java


Run:


D:\>java Sk23


Output:


*


***


*****


*******


*********


*******


*****


***


*





























Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C