Skip to content

Latest commit

 

History

History
29 lines (18 loc) · 599 Bytes

Ex_1_1_14.md

File metadata and controls

29 lines (18 loc) · 599 Bytes
title date draft tags categories
算法4 Java解答 1.1.14
2019-03-02 19:38:47 +0800
false
JAVA
技术
归档

1.1.14

问题:

Write a static method lg() that takes an int value N as argument and returns the largest int not larger than the base-2 logarithm of N. Do not use Math.

分析:

Use while loop to keep dividing the argument by 2 (base was 2), till it reaches zero.

Keep a count on the number of times the division by 2 was been performed.

Return the count - 1 as the program wants the largest integer not larger than log value.

参考: