fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15.  
  16. for(int i=0; i<n; i++){
  17. System.out. println(fibonacci(i));
  18. }
  19.  
  20. }
  21.  
  22. public static int fibonacci(int n){
  23.  
  24. if(n == 0){
  25. return 0;
  26. }
  27. else if(n == 1){
  28. return 1;
  29. }
  30. else {
  31. return fibonacci(n-2) + fibonacci(n-1);
  32. }
  33.  
  34. }
  35. }
Success #stdin #stdout 0.15s 56536KB
stdin
20
stdout
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181