Go to Top

Tuesday 14 February 2012

Visitors Request - 5

This was the program requested from me.

Question : To print the following pattern.

55555
54444
54333
54322
54321

Java Program :

class pattern_41
{
 static void pattern(int a)
 {
     int i,j,k;
     for(i=a;i>=1;i--)
     {
         for(j=a;j>i;j--)
         System.out.print(j);
         for(k=1;k<=i;k++)
         System.out.print(i);
         System.out.print("\n");
        }
    }
}

This is the program for it and as usual, I have included the option to extend the pattern to any length you enter.

No comments:

Post a Comment

ShareThis