SHARE
TWEET

Untitled

a guest Jun 28th, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. /**
  8.  * Created by Bludya on 28.6.2016 г..
  9.  * All rights reserved!
  10.  */
  11. class Fibonacci{
  12.     private List<Long> numbers;
  13.  
  14.     public Fibonacci(int end){
  15.         numbers = new ArrayList<>();
  16.         numbers.add(0l);
  17.         numbers.add(1l);
  18.         numbers.add(1l);
  19.  
  20.         for (int i = 3; i < end; i++) {
  21.             numbers.add(numbers.get(i-2) + numbers.get(i-1));
  22.         }
  23.     }
  24.  
  25.     public List<Long> getNumbersInRange(int start, int end){
  26.         return numbers.subList(start, end);
  27.     }
  28. }
  29. public class Problem05_FibonacciNumbers {
  30.     public static void main(String[] args) throws IOException{
  31.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  32.         int start = Integer.valueOf(reader.readLine());
  33.         int end = Integer.valueOf(reader.readLine());
  34.  
  35.         Fibonacci fibonacci = new Fibonacci(end);
  36.         System.out.println(fibonacci.getNumbersInRange(start, end).toString().replaceAll("[\\[\\]]",""));
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top