zhang_yan6

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

package demo;

import java.util.Scanner;

/*

 * 行数               空格                       星

 * 1           3             1

 * 2           2             3

 * 3           1             5

 * 4           0             7

 * */

public class Demo {

    public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       while(true){

           int rows = sc.nextInt();

          

           while(rows <= 0){

              System.out.println("结束!");

              break;

           }

          

           //外层循环行数

           for(int i = 1;i <= rows; i++){

               for(int j = 1; j<= rows-i; j++){

                  System.out.print(" ");

               }

               for(int z= 1;z <= (2*i)-1; z++){

                  if(z == 1 || z == (2*i-1)){

                      System.out.print("*");

                  }else{

                      System.out.print(" ");

                  }

                  

               }  

               System.out.println();

           }

          

           for(int i = rows-1;i >= 1; i--){

               for(int j = 1; j<= rows-i; j++){

                  System.out.print(" ");

               }

               for(int z= 1;z <= (2*i)-1; z++){

                  if(z == 1 || z == (2*i-1)){

                      System.out.print("*");

                  }else{

                      System.out.print(" ");

                  }

               }  

               System.out.println();

           }

       }

      

   

    }  

    }   

    

posted on 2018-11-23 16:25  zhang_yan6  阅读(344)  评论(0编辑  收藏  举报