黑马程序员技术交流社区

标题: 打印倒三角和正三角形 [打印本页]

作者: 奔跑的小红帽    时间: 2015-10-21 23:04
标题: 打印倒三角和正三角形
class Test2_1For {
/*打印如下图案
* * * * *
* * * *
  * * *
   * *
    *
*/
        public static void main(String []args){
                for(int x = 1; x <= 5;x++){
                        for(int y = 1;y < x; y++){
                                System.out.print(" ");
                        }
                        for(int z = 1; z<= 6-x;z++){
                                System.out.print("* ");
                        }
                        System.out.println();
                }
        }
}
class Test3_1For {
        /*

    *
   * *
  * * *
* * * *
* * * * *

*/
        public static void main(String []args){
                for(int x = 1;x <= 5;x++){
                        for(int y = 1;y <= 5-x;y++){
                                System.out.print(" ");
                        }
                        for(int z = 1; z <= x; z++){
                                System.out.print("* ");
                        }
                        System.out.println();
                }
        }
}






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2