Go to Top

Monday, 1 August 2011

To print a given pattern

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


5
54
543
5432
54321

Java Program : 

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

1 comment:

  1. I WANT A PROGRAM OF THIS AAS SSON AS POSSIBLE:
    10 9 8 7
    6 5 4
    3 2
    1

    ReplyDelete

ShareThis