print this image in java code using only loop{for, if, loop}

print this image in java code using only loop{for, if, loop}

*           *  *  *  *  *  
*           *              
*           *              
*           *              
*  *  *  *  *  *  *  *  *  
            *           *  
            *           *  
            *           *  
*  *  *  *  *           *  
View Answers

October 20, 2012 at 5:20 PM

Here is a code that displays the following pattern:

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



class SwastikPattern{
    public static void main(String[] args){

 char s[][]=new char[10][10];
 int i,j;

 for(i=0;i<9;i++)
 {
   for(j=0;j<9;j++)
   {
   s[i][j]='*';
   }
 }
 for(i=0;i<4;i++)
 {
   for(j=1;j<4;j++)
   {
   s[i][j]=' ';
   }
 }
 for(i=1;i<4;i++)
 {
   for(j=5;j<9;j++)
   {
   s[i][j]=' ';
   }
 }
 for(i=5;i<8;i++)
 {
   for(j=0;j<4;j++)
   {
   s[i][j]=' ';
   }
 }
 for(i=5;i<9;i++)
 {
   for(j=5;j<8;j++)
   {
   s[i][j]=' ';
   }
 }
 for(i=0;i<9;i++)
 {
   for(j=0;j<9;j++)
   {
     System.out.print("  "+s[i][j]);
   }
 System.out.println();
 }

}
    }









Related Tutorials/Questions & Answers:

Ads