Write a method called printPowersOf2 that accepts a maximum number as an argument and prints each power
Question:
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. For example, consider the following calls:
printPowersOf2(3);
printPowersOf2(10);
These calls should produce the following output:
1 2 4 8
1 2 4 8 16 32 64 128 256 512 1024
You may assume that the value passed to printPowersOf2 is 0 or greater. (The Math class may help you with this problem. If you use it, you may need to cast its results from double to int so that you don’t see a . 0 after each number in your output. Also try to write this program without using the Math class.)
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted: