Challenge: The Nearest Power of 2
Explore how to create a Java program that identifies the nearest power of 2 to a given number. Learn to apply loops and decision-making skills to solve this problem, handling cases where two powers of 2 are equally close. This lesson helps you practice logic development and strengthens your understanding of repetition structures in Java programming.
Task
Write a program that takes a positive number (num) and finds the power of nearest to that number. The program stores the resulting value to pwr.
If there are two candidate values, display the smaller one. For example, ...