Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Write a simple program

BunkerHillBroad
BunkerHillBroad 


file Powers.java Write a method named printPowersOf2 that accepts a maximum integer power as an argument and prints each power of 2 from 20 (which is equal to 1) up to that maximum power, inclusive. For example, printPowersOf2(10) should print 1 2 4 8 16 32 64 128 256 512 1024 You will need also to write a main program that convincingly demonstrates the printPowersOf2 method in action by asking the user to input from the keyboard the argument to be passed to printPowersOf2. Do NOT use any Math class methods in solving this problem! You should also not use any floats doubles or casting. Be careful: printPowersOf2(32) should print 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 Attachments
Tags Clarifications

Answers

Solution Power of 2

mariobeka
mariobeka 



Implemented as asked in the question. Attachments
Powers.java (1 K) Download Preview
printPowersOf2(int maxNumber) { long powerOfTwo = 1L; System.out.print(powerOfTwo); for (int i = 0; i <

Screenshots
Purchase Answer