黑马程序员_13 打印菱形

 



---------------------- ASP.Net+Android+IO开发S.Net培训、期待与您交流! ----------------------



                       打印菱形



根据要求打印相对应的图案


最少1个技术分,最高3个技术分




心动不如行动


快快行动吧






--------------------------------------------------------------------------------


题目


1.打印一个菱形
                    *                                
                   ***                        
                  *****                        
                 *******                
                *********                
                 *******
                  *****        
                   ***        
                    *        
2.打印两个菱形
                     *         *                
                   ***       ***                
                 *****     *****                
                *******  *******                 
               *****************                
                *******   *******
                 *****      *****
                  ***         ***
                   *            *
打印如图相邻的四个菱形                
                     *        *                
                   ***      ***                
                 *****    *****                
               *******  *******                 
              *****************                
               *******  *******
                 *****    *****
                   ***       ***
                    *          *                
                   ***         ***                
                 *****      *****                
               *******  *******                 
             *****************                
               *******  *******
                *****       *****
                  ***           ***
                    *               *                                
                   
这道题是我参加的黑马论坛的一个活动,打印菱形,现将部分思路和代码写下来,
先声明:本人在发帖时还是只小菜鸟,所以难免代码不够完美,还请高手谅解,
教诲。不胜感激。


另外,在这里万分感谢黑马训练营,感谢本活动的版主。


1.打印一个菱形
           *                                            
          ***                                                                                          
         *****                                                                                       
        *******                                                                  
       *********                                                                          
        *******                                                                 
          *****                                                                           
           ***                                                                                
            *                                                                                                        
 完整图形应该是 
    ****  *  ****
    ***  ***  ***
    **  *****  **
    *  *******  *
      *********
    *  *******  *
    **  *****  **
    ***  ***  ***
    ****  *  ****     
先做上一部分
  ****  *  ****
  ***  ***  ***
  **  *****  **
  *  *******  *     
    这部分是由四小部分组成
分解如下
 ****  *    ****
 ***  **  *  ***
 **  ***  **  **
 *  ****  ***  *
  下一部分分解如下
    ***** ****
  *  **** ***  *
  **  *** **  **
  ***  ** *  ***
  ****  *   ****                    
       
 public class Oss 
{
        public static void main(String[]args)
        {
                for(int x=1;x<5;x++)
                {
                        for(int y=x;y<5;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=0;z<x;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=1;a<x;a++)
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
                for(int x=1;x<6;x++)
                {
                        for(int y=1;y<x;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=x;z<6;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=x+1;a<6;a++)
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
        }
}
2.打印两个菱形
                      *           *                
                    ***         ***                
                   *****      *****                
                  *******   *******                 
                  *****************                
                  *******   *******
                   *****      *****
                     ***        ***
                      *           *
 public class Oss 
{
        public static void main(String[]args)
        {
                for(int x=1;x<5;x++)
                {
                        for(int y=x;y<5;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=0;z<x;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=1;a<x;a++)
                        {
                                System.out.print("*");
                        }
                        for(int y=x;y<5;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int b=x+1;b<5;b++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=0;z<x;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=1;a<x;a++)
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
                for(int x=1;x<6;x++)
                {
                        for(int y=1;y<x;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=x;z<6;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=x+1;a<6;a++)
                        {
                                System.out.print("*");
                        }
                        for(int y=1;y<x;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int b=1;b<x-1;b++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=x;z<6;z++)
                        {
                                if(z==1)
                                {
                                        z+=1;
                                }
                                System.out.print("*");
                        }
                        for(int a=x+1;a<6;a++)
                        {
                                System.out.print("*");
                        }


                        System.out.println();
                }
        }
}
3 打印四个
 public class Oss_1
{
        public static void main(String[]args)
        {
                for(int x=1;x<5;x++)
                {
                        for(int y=x;y<5;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=0;z<x;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=1;a<x;a++)
                        {
                                System.out.print("*");
                        }
                        for(int y=x;y<5;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int b=x+1;b<5;b++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=0;z<x;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=1;a<x;a++)
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
                for(int x=1;x<6;x++)
                {
                        for(int y=1;y<x;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=x;z<6;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=x+1;a<6;a++)
                        {
                                System.out.print("*");
                        }
                        for(int y=1;y<x;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int b=1;b<x-1;b++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=x;z<6;z++)
                        {
                                if(z==1)
                                {
                                        z+=1;
                                }
                                System.out.print("*");
                        }
                        for(int a=x+1;a<6;a++)
                        {
                                System.out.print("*");
                        }


                        System.out.println();
                }
                for(int w=1;w<4;w++)
                {
                        for(int y=w+2;y<6;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=0;z<w+1;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=0;a<w;a++)
                        {
                                System.out.print("*");
                        }
                        for(int y=w+2;y<6;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int b=w+2;b<5;b++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=1;z<w+1;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=0;a<w+1;a++)
                        {
                                System.out.print("*");
                        }
                        System.out.println();
                }
                for(int w=1;w<6;w++)
                {
                        for(int y=1;y<w;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=w;z<6;z++)
                        {
                                System.out.print("*");
                        }
                        for(int a=w+1;a<6;a++)
                        {
                                System.out.print("*");
                        }
                        for(int y=1;y<w;y++)
                        {
                                System.out.print(" ");
                        }
                        for(int b=1;b<w-1;b++)
                        {
                                System.out.print(" ");
                        }
                        for(int z=w;z<6;z++)
                        {
                                if(z==1)
                                {
                                        z+=1;
                                }
                                System.out.print("*");
                        }
                        for(int a=w+1;a<6;a++)
                        {
                                System.out.print("*");
                        }


                        System.out.println();
        }
}




}
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值