Advertisement
deyanmalinov

5. Calculate Sequence with Queue

May 8th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         long num = scan.nextLong();
  7.         Deque<Long> progres = new ArrayDeque<>();
  8.         progres.add(num);
  9.         for (int i = 0; i < 50; i++) {
  10.             Long element = progres.poll();
  11.             System.out.printf("%d ",element);
  12.             long s2 = element +1;
  13.             long s3 = 2*element + 1;
  14.             long s4 = element +2;
  15.             progres.add(s2);
  16.             progres.add(s3);
  17.             progres.add(s4);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement