Advertisement
roronoa

fibonacci

Aug 17th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Solution {
  5.     public static void main(String args[]) {
  6.         Scanner in = new Scanner(System.in);
  7.         int N = in.nextInt();
  8.         int n1=1, n2=1;
  9.         String f="";
  10.         for(int i=0; i<N; i++){
  11.             if(i==0) f+=0;
  12.             else if(i==1){
  13.                 f+=" "+1;
  14.                 n1=0; n2=1;
  15.             }else{
  16.                 f+=" "+(n1+n2);
  17.                 int a=n1;
  18.                 n1=n2; n2=(a+n2);
  19.             }
  20.         }
  21.         System.out.println(f);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement