小程序--显示图形效果
生活随笔
收集整理的這篇文章主要介紹了
小程序--显示图形效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//運用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的使用。
*/
/*運行的結果
----*
---* *
--* * *
-* * * *
* * * * *
-* * * *
--* * *
---* *
----*
*/
轉載于:https://www.cnblogs.com/alhh/p/5251843.html
總結
以上是生活随笔為你收集整理的小程序--显示图形效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【BZOJ1002】[FJOI2007]
- 下一篇: 转:fopen与open可以转换吗