Advertisement
3vo

Long Sequence

3vo
Mar 16th, 2023 (edited)
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Long Sequence
  3.  
  4. Write a program that prints the first 1000 members of the sequence: 2, -3, 4, -5, 6, -7, …
  5.  
  6.     You might need to learn how to use loops in Java (search in Internet).
  7.  
  8. Input
  9.  
  10.     There is no input for this task.
  11.  
  12. Output
  13.  
  14.     Output the first 1000 members of the sequence, each on a separate line.
  15. 2
  16.  
  17. -3
  18.  
  19. 4
  20.  
  21. -5
  22.  
  23. 6
  24.  
  25. ...
  26. */
  27. for (let num = 2; num <= 1002; num++) {
  28.  
  29.     if (num % 2 === 0) {
  30.         console.log(num);
  31.     } else {
  32.         console.log(num - (num * 2));
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement