desislava_topuzakova

04. Sequence 2k+1 (while цикъл)

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