class PrintExtend
{
public static void main(String[] args)
{
print(5,4);
}
//num指的菱形的大小,count代表横着菱形重复个数。
public static void printUp(int num,int count)
{
if(num<1||count<0)
{
System.out.println("哥么,别开玩笑。");
System.exit(0);
}
for (int x=1;x<num+1 ;x++ )
{
for (int y=1;y<num+1-x;y++ )
{
System.out.print(" ");
}
for (int z=1;z<2*x;z++)
{
System.out.print("*");
}
//
for (int co=0;co<=count;co++ )
{
for (int a=1;a<2*(num-x)+1;a++ )
{
System.out.print(" ");
}
for (int b=1;b<2*x ;b++ )
{
System.out.print("*");
}
}
//
for (int a=1;a<2*(num-x)+1;a++ )
{
System.out.print(" ");
}
for (int b=1;b<2*x ;b++ )
{
if (b==2*x-1)
System.out.println("*");
else
System.out.print("*");
}
}
for (int x=1;x<num ;x++ )
{
for (int y=1;y<x+1 ;y++ )
{
System.out.print(" ");
}
for (int z=1;z<2*(num-x);z++ )
{
System.out.print("*");
}
//
for (int co=0;co<=count;co++ )
{
for (int c=1;c<2*x+1;c++ )
{
System.out.print(" ");
}
for (int d=1;d<2*(num-x) ;d++ )
{
System.out.print("*");
}
}
//
for (int a=1;a<2*x+1;a++ )
{
System.out.print(" ");
}
for (int b=1;b<2*(num-x) ;b++ )
{
if (b==2*(num-x)-1)
System.out.println("*");
else
System.out.print("*");
}
}
}
public static void print(int num,int count)
{
printUp(num,count);
for (int x=1;x<num ;x++ )
{
for (int y=1;y<num-x;y++ )
{
System.out.print(" ");
}
for (int z=1;z<2*x+2;z++)
{
System.out.print("*");
}
//
for (int co=0;co<=count;co++ )
{
for (int a=1;a<2*(num-x)-1;a++ )
{
System.out.print(" ");
}
for (int b=1;b<2*x+2 ;b++ )
{
System.out.print("*");
}
}
//
for (int a=1;a<2*(num-x)-1;a++ )
{
System.out.print(" ");
}
for (int b=1;b<2*x+2 ;b++ )
{
if (b==2*x+1)
System.out.println("*");
else
System.out.print("*");
}
}
for (int x=1;x<num ;x++ )
{
for (int y=1;y<x+1 ;y++ )
{
System.out.print(" ");
}
for (int z=1;z<2*(num-x);z++ )
{
System.out.print("*");
}
//
for (int co=0;co<=count;co++ )
{
for (int c=1;c<2*x+1;c++ )
{
System.out.print(" ");
}
for (int d=1;d<2*(num-x) ;d++ )
{
System.out.print("*");
}
}
//
for (int a=1;a<2*x+1;a++ )
{
System.out.print(" ");
}
for (int b=1;b<2*(num-x) ;b++ )
{
if (b==2*(num-x)-1)
System.out.println("*");
else
System.out.print("*");
}
}
}
}
|