Saturday, June 25, 2011

Few Programs On Pattern Printing Using BlueJ


Here are few pattern printing programs. Students are advised to go through the programs and if they find any problem in understanding any program, they can put comments and I will clarify each and every statement of the programs. 

Pattern number 1


         _1____

   ___121___
   __12321__
   _1234321_
   123454321

 class Pat
 {
  int i,j,k,m,x=1;
  public void show()
  {
   for(i=0;i< 5;i++)
   {
   x=1;
   for(m=i;m< 4;m++)
   System.out.print(" ");
    for(j=0;j< =i;j++)
    {
     System.out.print(x++);
    
     }
        x=x-2;
    for(j=0;j< i;j++)
    {
     System.out.print(x--);
     }
   System.out.println();
   }
   }
   public static void main(String args[])
   {
    Pat ob=new Pat();
    ob.show();
    }
   }



Pattern number 2

  .____A
   ___AA
   __AAA
   _AAAA
   AAAAA
   _AAAA
   __AAA
   ___AA
   ____A


class Pat
 {
  int i,j,m,x=4;
  public void show()
  {
   for(i=0;i< 9;i++)
   {
      for(m=0;m< x;m++)
   System.out.print(" ");
    for(j=0;j< =4-x;j++)
    {
     System.out.print("A");
    
     }
       if(i< 8/2)
        x--;
     else
     x++;
   System.out.println();
   }
   }
   public static void main(String args[])
   {
    Pat ob=new Pat();
    ob.show();
    }
   }


Pattern number 3

   aaaaaaaaa
     bbbbbbb
      ccccc
        ddd
          e


class Pat
 {
  int i,j,m,y=9,x=97;
  public void show()
  {
   for(i=0;i< 5;i++)
   {
      for(m=0;m< i;m++)
   System.out.print(" ");
    for(j=0;j< y;j++)
    {
     System.out.print((char)x);
    
     }
        x++;
       y=y-2;

   System.out.println();
   }
   }
   public static void main(String args[])
   {
    Pat ob=new Pat();
    ob.show();
    }
   }

Pattern number 4

   54321
     4321
       321
         21
           1

class Pat
 {
  int i,j,m,x;
  public void show()
  {
   for(i=0;i< 5;i++)
   {
x=5-i;
      for(m=0;m< i;m++)
   System.out.print(" ");
    for(j=0;j< 5-i;j++)
    {
     System.out.print(x--);
    
     }
        
   System.out.println();
   }
   }
   public static void main(String args[])
   {
    Pat ob=new Pat();
    ob.show();
    }
   }


Related PostBlueJ Programs On Pattern

11 comments:

  1. @jit: Please post solutions for ISC 2009 Practical Papers

    ReplyDelete
  2. Programs of 2009 ISC practical are posted in this site with different title names. Please search the programs in my site and you will find those programs.

    ReplyDelete
  3. sir please approve my programs and please solve them i can't solve them

    ReplyDelete
  4. how to have such pattern in output using for statement ... plz help,, reqd urgently.
    output:

    123
    456
    789

    ReplyDelete
  5. class Pt
    {
    int i,j,x=1;
    public void show()
    {
    for( i=0; i < 3;i++)
    {
    for(j=0; j < 3;j++)
    {
    System.out.print(x++);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  6. aaaaaaaaaa
    aaaa aaaa
    aaa aaa
    aa aa
    a a
    aa aa
    aaa aaa
    aaaa aaaa
    aaaaaaaaaa

    pls solve this one.

    ReplyDelete
  7. public class Pattern
    {
    int i,j,k,y=5;
    public void show()
    {
    for(i=0;i< 9;i++)
    {
    for(j=0;j< y;j++)
    System.out.print("a");
    if(i!=0 && i!=8)
    {
    for(j=0;j< 1;j++)
    System.out.print(" ");
    }
    for(k=0;k< y;k++)
    System.out.print("a");
    System.out.println();
    if(i>=9/2)
    y++;
    else
    y--;
    }
    }
    public static void main(String args[])throws Exception
    {
    Pattern ob=new Pattern ();
    ob.show();
    }
    }

    ReplyDelete
  8. Can any1 teach me please? my boards are approaching! :(

    ReplyDelete
  9. Go through my site from the first page and if any doubt, post in comments section - I will help you. This much I can do for you.

    ReplyDelete
  10. Superb site...quite helpful

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner