- public class Test{
- /*
- 1
- 1 1
- 1 2 1
- 1 3 3 1
- 1 4 6 4 1
- 1 5 10 10 5 1
- 1 6 15 20 15 6 1
- */
- public static void main(String[] args){
- print(12);
- }
- static void print(int sum){
- //声名二维数组,实例化一维数组,长度为sum,
- int[][] a=new int[sum][];
- for (int i = 0; i <a.length; i++) {
- //实例化二维数组!
- a[i]=new int[i+1];
- //给二维数组赋值, 首 为1!
- a[i][0]=1;
- // 给二维数组赋值, 首 尾除外!
- for (int j = 1; j <a[i].length-1; j++) {
- a[i][j]=a[i-1][j-1]+a[i-1][j];
- }
- //给二维数组赋值, 尾为1!
- a[i][a[i].length-1]=1;
- }
- //输出
- for (int i = 0; i < a.length; i++) {
- for (int j = 0; j < a[i].length; j++) {
- System.out.print(print1(a[i][j]));
- }
- System.out.println();
- System.out.println();
- }
- }
- static String print1(int a)
- {
- if (a<=9) {
- return " "+a+" ";
- }
- else if (a>=10&&a<100) {
- return a/10+" "+a%10+" ";
- }else
- {
- return a+" ";
- }
- }
- }