Advertisement
Spocoman

04. Sequence 2k+1

Aug 28th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 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 k = 1;
  8.  
  9.         while (k <= n) {
  10.             System.out.println(k);
  11.             k = 2 * k + 1;
  12.         }
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement