Advertisement
desislava_topuzakova

04. Even Powers of 2

Mar 26th, 2023
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 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.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. //степени от 0 до n
  9. //повтарям: проверка дали степента е четна => отпечатвам 2 на дадената степен
  10. //начало: 0
  11. //край: n
  12. //промяна: +1
  13.  
  14. for (int power = 0; power <= n; power++) {
  15. if (power % 2 == 0) {
  16. System.out.println(Math.pow(2, power));
  17. }
  18. }
  19. }
  20. }
  21.  
  22.  
  23. import java.util.Scanner;
  24.  
  25. public class EvenPowersOf2_04 {
  26. public static void main(String[] args) {
  27. Scanner scanner = new Scanner(System.in);
  28.  
  29. int n = Integer.parseInt(scanner.nextLine());
  30. //четни степени от 0 до n (0, 2, 4, 6, 8, ...)
  31. //повтарям: отпечатвам 2 на дадената степен
  32. //начало: 0
  33. //край: n
  34. //промяна: +2
  35.  
  36. for (int power = 0; power <= n; power += 2) {
  37. System.out.println(Math.pow(2, power));
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement