Advertisement
desislava_topuzakova

04. Sequence 2k+1 (решение с For)

May 28th, 2023
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Sequence_04 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7.  
  8. //1 до n, които се променят * 2 + 1
  9.  
  10. //for цикъл
  11. //повтаряме: отпечатваме число
  12. //начало: 1
  13. //край: n
  14. //промяна: * 2 + 1
  15.  
  16. for (int number = 1; number <= n; number = number * 2 + 1) {
  17. System.out.println(number);
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement