黑马程序员技术交流社区
标题:
新手,写了个关于数字塔形的代码
[打印本页]
作者:
breaveheart
时间:
2013-7-18 17:08
标题:
新手,写了个关于数字塔形的代码
看了毕老师关于输出星形形状的代码,自己参照写了个数字塔形的供大家看看。
新手可能有疏漏,有好想法的欢迎大家批评建议。{:soso_e100:}
输出效果:
塔形.jpg
(10.89 KB, 下载次数: 0)
下载附件
2013-7-18 17:07 上传
代码:
class taxing
{
public static void main(String[] args)
{
int x,y,z;
for(x=1;x<=4;x++)
{
for(y=7-x;y>=1;y--)
{
System.out.print(" ");
}
for(z=1;z<=x;z++)
{
System.out.print(z+" ");
}
for (int a=x-1; a>0;a-- )
{
if(a==x-1)
System.out.print(a);
else
System.out.print(" "+a);
}
System.out.println();
}
}
}
复制代码
作者:
breaveheart
时间:
2013-7-18 17:12
占个沙发道个歉,新手第一次用代码粘贴,以为直接排版,不好意思哈大家。重新发代码。
<P> </P>
复制代码
class taxing
{
public static void main(String[] args)
{
int x,y,z;
for(x=1;x<=4;x++)
{
for(y=7-x;y>=1;y--)
{
System.out.print(" ");
}
for(z=1;z<=x;z++)
{
System.out.print(z+" ");
}
for (int a=x-1; a>0;a-- )
{
if(a==x-1)
System.out.print(a);
else
System.out.print(" "+a);
}
System.out.println();
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2