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;
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