Thursday, January 9, 2014

Pattern of numbers

/*
Write a java program
to print the following
pattern of numbers
Use nested loop.

1 3 5 7
3 5 7
5 7
7

*/

class p410
{
        public static void main(String args[])
        {
                int i,j,k=3;
                for(i=1;i<=7;i+=2)
                {  
                    for(j=0;j<=k;j++)
                       System.out.print(i+(j*2) + " ");
                    k--;
                    System.out.println();
                }
        }
}

No comments:

Post a Comment