Saturday, August 30, 2014

BlueJ Program To Print A Pattern On Numbers


The pattern is as follows:
1
121
12321
1234321
123454321
1234321
12321
121
1

import java.io.*;
class Pattern
{
 int i,j,x,n,m=1;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 void show() throws Exception
 {
      System.out.println("\nHow many rows:");
      n=Integer.parseInt(br.readLine());
      for(i=0;i< m;i++)
      {
          x=1;
           for(j=0;j< m;j++)
           {
                System.out.print(x);
                if (j< m/2)
                x++;
                else
                x--;
            }
            System.out.println();
            if(i< n/2)
            m=m+2;
            else
            m=m-2;
           
        }
    }
    public static void main(String args[])throws Exception
    {
         Pattern ob=new Pattern ();
         ob.show();
        }

    }


Related PostBlueJ Programs On Pattern

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner