参考代码:

import java.util.Scanner;


public class Main1131 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int x = sc.nextInt();

int a[] = new int[x];


for (int i = 0; i < a.length; i++) {

if (i == 0 || i == 1) {

a[i] = 1;

} else {

a[i] = a[i - 1] + a[i - 2];

}

}

for (int y : a) {

System.out.print(y + " ");

}

}

}


 

0.0分

1 人评分

  评论区