public class Test {
public static void main(String[] args) {
int n = 10;
int[] last = new int[n];
for (int i = 0; i < n; ++i)
last[i] = 1;
int[] current = last.clone();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < i - 1; ++j) {
current[j] = last[j] + last[j - 1];
}
print(current, i , n);
int[] t = current;
current = last;
last = t;
}
}
static void print(int[] array, int n ,int x) {
//打印空格
if(n%2==1)System.out.print(" ");
int y=x+(x+1)%2;
for (int i = n; i < y; i=i+2) {
System.out.print(" ");
}
//打印图形,无改动
for (int i = 0; i < n; ++i){
System.out.print(aaa(array[i]));
}
System.out.println();
}
//打印数字和数字后面空格
static String aaa(int x)
{
String str=Integer.toString(x);
for (int i = str.length(); i < 6 ; i++) {
str=str+" ";
}
return str;
}
} |