打印一个镂空的菱形。
*
* *
* *
* *
* *
* *
* *
* *
*
class DemoTest
{
public static void main(String[] args)
{
for (int x = 1;x<=5 ;x++ )
{
for (int y = x;y<=4 ;y++ )
{
System.out.print(" ");
}
for (int z =1 ;z<=x ;z++ )
{
if(z==1||z==x)
System.out.print("* ");
else
System.out.print(" ");
}
System.out.println();
}
for (int x =4;x>=1 ;x-- )
{
for (int y = 1;y<=5-x ;y++ )
{
System.out.print(" ");
}
for (int z = 1;z<=x ; z++)
{
if(z==1||z==x)
System.out.print("* ");
else
System.out.print(" ");
}
System.out.println();
}
}
}
|
|