Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PredvaritelnoAdvanced.StacksAndQueues.classTwo;
- import java.util.ArrayDeque;
- import java.util.Scanner;
- public class G_RecursiveFibonacci_07 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- ArrayDeque<Long> stack = new ArrayDeque<>();
- for (int i = 0; i < num + 1; i++) {
- if (i <= 1) {
- stack.push(1L);
- } else {
- long numOne = stack.pop();
- long numTwo = stack.pop();
- long numThree = numOne + numTwo;
- stack.push(numTwo);
- stack.push(numOne);
- stack.push(numThree);
- }
- }
- System.out.println(stack.peekFirst());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement