Tuesday, July 24, 2012

Star Pattern using for loop


class star
{

 public static void main(String arg[])
 { 
  int a,b,c;


  System.out.println("\n\nPattern 01\n\n");
  
  for(a=1;a<6;a++)
  {
   for(b=0;b<a;b++)
   {
    System.out.print("*");
   }

   System.out.print("\n");
  }


  System.out.println("\n\nPattern 02\n\n");
  
  for(a=1;a<6;a++)
  {
   for(b=6;b>a;b--)
   {
    System.out.print("*");
   }

   System.out.print("\n");
  }

    
  System.out.println("\n\nPattern 03\n\n");
  
  for(a=1;a<6;a++)
  {
   for(b=0;b<a;b++)
   {
    System.out.print(" ");
   }

   for(c=6;c>a;c--)
   {
    System.out.print("*");
   }

   System.out.print("\n");
  }


  System.out.println("\n\nPattern 04\n\n");
  
  for(a=1;a<6;a++)
  {
   for(b=6;b>a;b--)
   {
    System.out.print(" ");
   }
   
   for(c=0;c<(2*a-1);c++)
   {
    System.out.print("*");
   }

   System.out.print("\n");
  }

 }

}




No comments:

Post a Comment

"You can always tell a real friend: when you've made a fool of yourself he doesn't feel you've done a permanent job."
- Laurence J. Peter

A friend always guide you to your destination, without leaving you in darkness...
Here I am, waiting for your precious comment, which gives strength to my writing.