在Java中利用循环语句实现杨辉三角
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入杨辉三角的行数:");
int n = in.nextInt();
for (int i = 1; i < n + 1; i++) {
for (int k = 0; k < n - i; k++) {
System.out.print(" ");
}
for (int j = 0; j < i; j++) {
System.out.print("* ");
}
System.out.println("");
}
}
网友评论