Sunday, September 21, 2014

BlueJ Program Pattern On Stars


In this program the pattern as shown below will be displayed using BlueJ program.

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


import java.io.*;
class Star
{


 int i,x=1,j,n;

 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 void show() throws Exception
 {
         System.out.print("\nHow many rows:");
        n=Integer.parseInt(br.readLine());
       
         for(i=0;i< n;i++)
         {
           
            for(j=0;j< x;j++)
            {
            System.out.print("*");
        }
            if(i< n/2)
            x++;
            else
           x--;
            System.out.println();
        }
        }
       
    public static void main(String args[])throws Exception
    {
         Star ob=new Star();
         ob.show();
        }
    }

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner