I just looked your problem up and read the directions. Using java:
public class JavaApplication63 {
public static void printPowersOf2(int maximum){
for (int i = 0; i <= maximum; i++){
int num = 1, w = 0;
if (i == 0){
System.out.print(0+" ");
}
else{
while (w < i){
num *= 2;
w++;
}
}
System.out.print(num+" ");
}
}
public static void main(String[] args) {
printPowersOf2(8);
}
}
In my code, we don't use the math class. I hope this helps!