fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int N = sc.nextInt();
  7.  
  8. long a = 0, b = 1;
  9.  
  10. for (int i = 1; i <= N; i++) {
  11. if (i == 1) {
  12. System.out.print(a);
  13. } else if (i == 2) {
  14. System.out.print(" " + b);
  15. } else {
  16. long temp = a + b;
  17. System.out.print(" " + temp);
  18. a = b;
  19. b = temp;
  20. }
  21. }
  22. sc.close();
  23. }
  24. }
  25.  
Success #stdin #stdout 0.21s 56872KB
stdin
5
stdout
0 1 1 2 3