Question #2525

Write a function called powersOfTwo that prints the first 10 powers of 2 (starting with 2). The function takes no parameters and doesn't return anything.

Expert's answer

public class Power {
& public static void powersOfTwo() {
for (int i = 2; i<11; i++) {
System.out.println(i + " power = " + Math.round(Math.pow(2, i)));
}
& }
public static void main(String[] args) {
powersOfTwo();
& }
}

LATEST TUTORIALS
APPROVED BY CLIENTS