好的,这是一份用Java语言打印杨辉三角的代码:
import java.util.Scanner;
public class PascalTriangle {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("请输入杨辉三角的行数:");
int rows = scan.nextInt();
for (int i = 0; i < rows; i++) {
int number = 1;
System.out.format("%" + (rows - i) * 2 + "s", "");
for (int j = 0; j <= i; j++) {
System.out.format("%4d", number);
number = number * (i - j) / (j + 1);
}
System.out.println();
}
}
}