杨辉三角形初学者的必看源码

tech2024-11-04  10

public class Question { /** * 题目:打印出杨辉三角形 */ public static void main(String[] args) { int lines = 6; int[] a = new int[lines + 1]; int previous = 1; for (int i = 1; i <= lines; i ++){ //空格 for (int j = lines; j > i; j--) { System.out.print(" "); } for (int j = 1; j <= i; j++){ int current = a[j]; a[j] = previous + current; previous = current; System.out.print(a[j] + " "); } System.out.println(); } }
最新回复(0)