Java--输出倒金字塔和正金字塔

*******

 ***** 

  *** 

   *

  ***

 *****

*******

package pp;

public class picture {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
    /*    int i,j,k;
        for(i=7;i>=1;i-=2)
        {
            for(k=1;k<=(7-i)/2;k++)
            {
                System.out.print("  ");
            }
            for(j=1;j<=i;j++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }
        
        for(i=2;i<=7;i+=2)
        {
            for(k=1;k<=(7-i)/2;k++)
            {
                System.out.print("  ");
            }
            for(j=1;j<=i+1;j++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }     */
        
        int i,j,l,k;
        
        for(l=0;l<=6;l++)
        {
            if(l>=0 && l<=2)
            {
                for(i=0;i<l;i++)
                {
                    System.out.print("  ");
                }
                for(j=1;j<=7-2*l;j++)
                {
                    System.out.print("* ");
                }
                System.out.println();
            }
            
            else if(l==3)
            {
                for(i=1;i<=3;i++)
                {
                    System.out.print("  ");
                }
          
                
                    System.out.print("* ");
                    System.out.println();
            }
            
            else
            {
                for(i=1;i<=6-l;i++)
                {
                    System.out.print("  ");
                }
                for(j=1;j<=l-(5-l);j++)
                {
                    System.out.print("* ");
                }
                System.out.println();
            }
                
            
        }

    }

}

 

posted @ 2020-12-22 00:24  zhou小月  阅读(399)  评论(0编辑  收藏  举报