public class test {
public static void main(String[] args) {
//128等于2的7次方,所以判定退出循环是i < 8
for (int i = 0; i < 8; i++) {
for (int j = 0; j <= i; j++) {
//Math.pow(2, j) 幂运算
System.out.print((int)Math.pow(2, j) + " ");
}
for (int j = i - 1; j >= 0; j--) {
System.out.print((int)Math.pow(2, j) + " ");
}
System.out.println();
}
}
}
输出结果
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 …128… 4 2 1 |
|