Go to Top

Monday, 1 August 2011

To print the given pattern

Question 20 : Write a program in Java to print the following pattern : 


5
44
333
2222
11111

Java Program : 

public class pattern_7
{
 public static void main()
 {
     int i,j;
     for(i=5;i>=1;i--)
     {
         for(j=5;j>=i;j--)
         {
             System.out.print(i);
            }
            System.out.print("\n");
        }
    }
}

1 comment:

ShareThis