规律数字方阵

public static void main(String[] args) {
fx(4);       //设置方阵大小
}
private static void fx(int n) {
int A = 0;   //设置初始变量
for (int i = 1; i <= n; i++) {
A = i + 4; //设置第一次 j>1时需要的打印值
for (int j = 1; j <= n; j++) {
if (j == 1) {
System.out.print(String.format("%02d ", i));//第一竖列打印值
} else {
System.out.print(String.format("%02d ", A));//后面竖列打印值
A += 4;
}
}
System.out.println();//每一行打印完后,自动换行
}

}

如图所示:

猜你喜欢

转载自blog.csdn.net/chenxiaoscode/article/details/77941786