In this program, the following pattern will be displayed.
*------------*
--*--------*
----*----*
------ *
----*-----*
--*---------*
*-------------*
import java.io.*;
class StarPattern
{
int i,j,n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void show() throws Exception
{
while(true)
{
System.out.print("\nHow many rows (should be odd):");
n=Integer.parseInt(br.readLine());
if(n%2!=0)
break;
}
for(i=0;i< n;i++)
{
for(j=0;j< n;j++)
{
if (i==j || i+j==n-1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
public static void main(String args[])throws Exception
{
StarPattern ob=new StarPattern();
ob.show();
}
}
Related Post: BlueJ Programs On Pattern
No comments:
Post a Comment