desislava_topuzakova

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

Oct 9th, 2021
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 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.         for (int number = 1; number <= n; number = number * 2 + 1) {
  12.             System.out.println(number);
  13.         }
  14.  
  15.  
  16.  
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment