martinvalchev

Sequence 2k+1

Nov 21st, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Sequence2kPlus1 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.          int n = Integer.parseInt(scanner.nextLine());
  7.          int num = 1;
  8.         System.out.println(num);
  9.         num = num *2 +1;
  10.         while (num <= n) {
  11.             System.out.println(num);
  12.             num = num * 2 + 1;
  13.         }
  14.  
  15.  
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment