金字塔形状的斐波那契数列java
时间: 2024-01-11 20:22:12 浏览: 134
以下是一个用Java编写的金字塔形状的斐波那契数列的例子:
```java
import java.util.Scanner;
public class FibonacciPyramid {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入金字塔的行数:");
int rows = scanner.nextInt();
int a = 0, b = 1, c;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print(a + " ");
c = a + b;
a = b;
b = c;
}
System.out.println();
}
}
}
```
阅读全文