desislava_topuzakova

04. Even Powers of 2

Jun 26th, 2021
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 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.         int n = Integer.parseInt(scanner.nextLine());
  7.         //степени от 0 до n, които са четни
  8.         //начална стойност: 0
  9.         //крайна стойност: n
  10.         //повтаряме: печатаме 2 на степен
  11.         //промяна: + 2
  12.  
  13.         for (int step = 0; step <= n; step += 2) {
  14.             System.out.printf("%.0f%n",Math.pow(2, step));
  15.         }
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment