Today we had class last block of the day, and it was my turn to go up to the genius bar with Tommy. Although, like most days, we didn't receive any customers, Preston did come up from the classroom with a question to ask me (I forget about what exactly).
It was a good day. I completed what was probably the hardest problem in Array 2: the FizzBuzz problem. However, I needed to go down to the classroom and ask for Mr. Daly's help to complete it. Without him, there's no way I could've done it.
It was very complicated for me in the sense that it used almost everything that I learned throughout Array 2, and it included a String array, which I had never worked with before, so I didn't know how they worked.
I am actually looking forward to going back to strings so that the problems will be easier to solve for the most part until I reach the end - I'm tired of such complex problems.
Here it is (it's a long one):
----------------------------------------------------------------------------------------------------------------------------------
This is slightly more difficult version of the famous FizzBuzz problem which is sometimes given as a first problem for job interviews. (See also: FizzBuzz Code.) Consider the series of numbers beginning at start and running up to but not including end, so for example start=1 and end=5 gives the series 1, 2, 3, 4. Return a new String[] array containing the string form of these numbers, except for multiples of 3, use "Fizz" instead of the number, for multiples of 5 use "Buzz", and for multiples of both 3 and 5 use "FizzBuzz". In Java, String.valueOf(xxx) will make the String form of an int or other type. This version is a little more complicated than the usual version since you have to allocate and index into an array instead of just printing, and we vary the start/end instead of just always doing 1..100. fizzBuzz(1, 6) → {"1", "2", "Fizz", "4", "Buzz"} fizzBuzz(1, 8) → {"1", "2", "Fizz", "4", "Buzz", "Fizz", "7"} fizzBuzz(1, 11) → {"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz"} |
---------------------------------------------------------------------------------------------------------------------------------
On Friday, we have a short class, but its a great opportunity to finish Array 2 finally and move on, which is what I plan on doing. |
No comments:
Post a Comment