class Demo
{
public static void main(String[] args)
{
for (int a=0;a<5;a++ )
{
for (int b=5;b>0;b-- )
{
if (b<=a+1)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
输出结果:
因为看了明月的两个for打印图形c
图形c:
*
* *
* * *
* * * *
* * * * *
我之前写的比较乱,但是唯一有点收获的就是,两个for嵌套在一个for中是平行关系,从上往下。而明月的代码告诉我,要多优化代码。逻辑思维尤其重要。
在这里感谢QQ好友明月,如果你有什么有趣的题目请往这里砸过来
转载请注明出处,谢谢!作者:逝秋http://blog.csdn.net/vvqiu