急求用java怎么输出一下数字方阵,请高手帮帮忙啊!!!

来源:百度知道 编辑:UC知道 时间:2024/09/20 23:30:15
064 032 016 008 016 032 064
032 016 008 004 008 016 032
016 008 004 002 004 008 016
008 004 002 001 002 004 008
016 008 004 002 004 008 016
032 016 008 004 008 016 032
064 032 016 008 016 032 064

public static void main(String[] args) throws Exception {
for (int i = 0; i <= 6; i++) {
for (int j = 0; j <= 6; j++) {
int m = (int) Math.pow(2, Math.abs(i - 3));
int n = (int) Math.pow(2, Math.abs(j - 3));
System.out.format("%03d ", m * n);
}
System.out.println();
}
}

给你一个好的算法,自己对齐一下打印。感觉我们像是有一个共同的老师

public class SqureTest {
public static double aMethod(double a) {
return Math.pow(2, Math.abs(a));
}

public static double bMethod(double a, double b) {
return SqureTest.aMethod(a) * SqureTest.aMethod(b);
}

public static void cMethod(double a, double b) {
int rs = (int) SqureTest.bMethod(a, b);
System.out.print(rs);
System.out.print(" ");
}

public static void main(String[] args) {
double n = 3;
for (double i = -n; i <= n; i++) {
for (double j = -n;