Advertisement
desislava_topuzakova

4. Редица числа 2K+1 (с while)

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