SHARE
TWEET

Untitled

a guest May 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package PredvaritelnoAdvanced.StacksAndQueues.classTwo;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Scanner;
  5.  
  6. public class G_RecursiveFibonacci_07 {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         int num = Integer.parseInt(scanner.nextLine());
  11.         ArrayDeque<Long> stack = new ArrayDeque<>();
  12.         for (int i = 0; i < num + 1; i++) {
  13.             if (i <= 1) {
  14.                 stack.push(1L);
  15.             } else {
  16.                 long numOne = stack.pop();
  17.                 long numTwo = stack.pop();
  18.                 long numThree = numOne + numTwo;
  19.                 stack.push(numTwo);
  20.                 stack.push(numOne);
  21.                 stack.push(numThree);
  22.             }
  23.         }
  24.         System.out.println(stack.peekFirst());
  25.     }
  26. }
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