public class Star {
public static void main(String[] args) {
int i,j,space,rows=5,k=0;
for(i=1;i<=rows;++i)
{
for(space=1;space<=rows-i;++space)
{
System.out.print(" ");
}
while(k!=2*i-1)
{
System.out.print("* ");
++k;
}
k=0;
System.out.print("\n");
}
for(i=rows-1;i>=1;--i)
{
for(space=0;space
System.out.print(" ");
for(j=i;j<=2*i-1;++j)
System.out.print("* ");
for(j=0;j
System.out.print("* ");
System.out.print("\n");
}
}
}
output:
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
public static void main(String[] args) {
int i,j,space,rows=5,k=0;
for(i=1;i<=rows;++i)
{
for(space=1;space<=rows-i;++space)
{
System.out.print(" ");
}
while(k!=2*i-1)
{
System.out.print("* ");
++k;
}
k=0;
System.out.print("\n");
}
for(i=rows-1;i>=1;--i)
{
for(space=0;space
System.out.print(" ");
for(j=i;j<=2*i-1;++j)
System.out.print("* ");
for(j=0;j
System.out.print("* ");
System.out.print("\n");
}
}
}
output:
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
No comments:
Post a Comment