desislava_topuzakova

04. Even Powers of 2

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