Respuesta :

Answer:  Write a method called printPowersOf2 that accepts a maximum number as an argument and prints

* each power of 2 from 20 (1) up to that maximum power, inclusive.

*/

public static void printPowersOf2(int max) {

   for (int i = 0; i <= max; i++) {

       System.out.print((int) Math.pow(2, i) + " ");

   }

   

   System.out.println();

Explanation:

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!

ACCESS MORE
EDU ACCESS