desislava_topuzakova

04. Even Powers of 2

Oct 2nd, 2021
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EvenPowersOf2_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         //всички четни степени от 0 до n
  8.         //повтарям: вдигам числото на дадената степен
  9.         //начална стойност: 0
  10.         //крайна стойност: n
  11.         //промяна: += 2
  12.         for (int step = 0; step <= n; step += 2) {
  13.             //2 ^ step
  14.             System.out.printf("%.0f%n", Math.pow(2, step));
  15.         }
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment