This lab will give you practice using the expressions and control structures that we discussed in lecture. Recall that expressions are parts of statements that instruct the computer to perform some computation. We also starting looking at if and switch control structures along with while, do, and for looping structures. Furthermore, we also discussed the Scanner class for obtaining input from the user.
log10 123456 = 5.091512206277716810 meaning
105.091512206277716810 = 123456
If we're dealing strictly with integer values, then we obviously need to round this value using a floor or ceiling function. For the purposes of this lab, consider the floor function such that:
floor(log10 123456) = 5
floor(log2 128) = 7
One way of calculating floor(logb X) is by repeated
integer division. Continually divide by b until the quotient is less than the
base. The number of divisions performed is equal to the result of the floor of
the log. For example:
123456 / 10 = 12345 / 10 = 1234 / 10 = 123 / 10 = 12 / 10 = 1 => 5 divisions
128 / 2 = 64 / 2 = 32 / 2 = 16 / 2 = 8 / 2 = 4 / 2 = 2 / 2 = 1 => 7 divisions
Write a Java program that computes the floor of the log as described above. Your program should do the following:
Test your program with different inputs to be sure it all works correctly.
When done, submit it to the lab2 subdirectory of the course
submissions site.
You'll need to use nested loops for this problem. However, the exact combination of loops can very from solution to solution. Spend some time planning how you're program is going to work. Look at the class examples posted on the course website for help.