Home Answers Viewqa Java-Beginners print this image in java code using only loop{for, if, loop}

 
 


vijay jaiswal
print this image in java code using only loop{for, if, loop}
1 Answer(s)      7 months ago
Posted in : Java Beginners

*           *  *  *  *  *  
*           *              
*           *              
*           *              
*  *  *  *  *  *  *  *  *  
            *           *  
            *           *  
            *           *  
*  *  *  *  *           *  
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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.