首页 > 其他 > 详细

小程序--显示图形效果

时间:2016-03-07 22:15:12      阅读:251      评论:0      收藏:0      [点我收藏+]

//运用for循环嵌套循环知识

class Alhh{
public static void main(String[] args){
for(int i=0;i<5;i++){//控制行数
for(int j=0;j<4-i;j++){//用-代替空格
System.out.print("-");
}
for(int k=0;k<i+1;k++){//*的个数
System.out.print("* ");
}
System.out.println();//换行
}
for(int i=0;i<4;i++){
for(int j=0;j<i+1;j++){
System.out.print("-");
}
for(int k=0;k<4-i;k++){
System.out.print("* ");
}
System.out.println();
}
}
}
/*注:1:for循环里面的变量只适用当前的for循环,下一个for循环用同样的变量不会因重名而出现错误。
* 2:注意换行println的使用。
*/

/*运行的结果
----*
---* *
--* * *
-* * * *
* * * * *
-* * * *
--* * *
---* *
----*

*/

小程序--显示图形效果

原文:http://www.cnblogs.com/alhh/p/5251843.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!