Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Monday, 4 July 2011

Program to Implement Number Pattern in Java

class Pattern
{
                public static void main(String args[])
                {
                                int twod[][]=new int[4][];
                                twod[0]=new int[1];
                                twod[1]=new int[2];
                                twod[2]=new int[3];
                                twod[3]=new int[4];

                                int i,j,k=0;
                                for(i=0;i<4;i++)
                                {
                                                for(j=0;j<i+1;j++)
                                                {
                                                                twod[i][j]=k;
                                                                k++;
                                                }
                                }
                                for(i=0;i<4;i++)
                                {
                                                for(j=0;j<i+1;j++)
                                                {
                                                                System.out.print(twod[i][j] + " ");
                                                }
                                                System.out.println();
                                }
                               
                }
}


Output:
0
1 2
3 4 5
6 7 8 9

No comments:

Post a Comment

Followers