Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Complete the method to find the largest power of 2 less than the given number
- * Use a loop
- */
- public class MathUtil
- {
- public int largestPowerOf2(int n)
- {
- double pow = 0;
- while ( Math.pow(2, pow) < n)
- {
- // pow = Math.pow(2.0, pow);
- //pow = pow * 2;
- pow++;
- }
- return (int)pow;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement