desislava_topuzakova

4. Четни степени на 2

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