初学者希望好心人帮忙解决一下

解决方案 »

  1.   

    class Demo{
    public static void main(String args[]){
      try{
    int k = Integer.parseInt(args[0]);
    fun( k );
      }catch(Exception e){
      System.out.println("请输入整数");
      } 
    }


    public static void fun(int n){
    if(n <= 0){
    System.out.println("不能输出0行或者负数行");
    }
    for(int i = 1; i <= n; i++){//控制输出的行数
    for(int y = 0; y < n - i; y++ ){
    System.out.print("   ");
    }
    for(int j = 1; j <= i; j++){
    System.out.print(j + "  ");
    }
    for(int x = i -1; x > 0; x--){
    System.out.print(x + "  " );
    }
    System.out.println();
    }
    }
    }