Go to Top

Tuesday 2 August 2011

To print the given pattern

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

*****
****
***
**
*

Java Program : 

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

No comments:

Post a Comment

ShareThis