1
      2 1 2
    3 2 1 2 3
  4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5这个数字三角怎么用java实现??

解决方案 »

  1.   


    public static void main(String[] args) throws Exception {
    int row = 9;  //行数,可任意修改
    String margin =" "; //数字见得空白
    for(int i = 1; i <= row; i++){
    for(int j = 0; j < row - i; j++){
    System.out.print(margin+margin);
    }
    for(int j = i; j > 0; j--){
    System.out.print(j+margin);
    }
    for(int j = 2; j <= i; j++){
    System.out.print(j+margin);
    }
    System.out.println();
    }
    }