Advertisement
desislava_topuzakova

4. Редица числа 2K+1 - с for цикъл

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