黑马程序员技术交流社区
标题:
分享一个打印的空心菱形方法。
[打印本页]
作者:
liya7907
时间:
2015-5-14 18:59
标题:
分享一个打印的空心菱形方法。
class Demo
{
main()
Scanner sc = new Scanner(System.in);
int n = 6;
while (n !=0)
{
System.out.print("n = ");
n = sc.nextInt();
int o = 2*n-1;
for (int x = 1;x <=n ;x++)
{
for (int y =x+1;y <=n ;y++)
{
System.out.print(" ");
}
System.out.print("* ");
for (int m =3;m <=x ;m++ )
{
System.out.print(" ");
}
if (x>1)
{
System.out.print("*");
}
System.out.println();
}
for (int a = n+1;a <=o ;a++ )
{
for (int b =n+1;b <=a ;b++ )
{
System.out.print(" ");
}
System.out.print("* ");
for (int d =a;d <=2*n-3 ;d++ )
{
System.out.print(" ");
}
if(a<o)
{
System.out.print("* ");
}
System.out.println();
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2