CodingBat is a website containing a couple hundred exercises for the Java and Python programming languages. It is run by Stanford professor Nick Parlante. You may know him from Google’s Python Class or the “Binky Pointer Fun Video.” Last year, he taught Computer Science 101 on Coursera.
CodingBat is a great resource if you’re starting out with programming. It can also serve as an excellent confidence builder if you’re not sure whether to take some computer science classes in college. If you can make your way through that website, you should find a typical first and second course in computer science to be quite manageable. In my case, I used it to supplement CS106A: Programming Methodology, which is hosted at Stanford Engineering Everywhere and Allen B. Downey’s book Think Java.
There are many CodingBat solutions floating around on the Internet already. What I’ve found, though, was that some were quite badly written and rather verbose. I also came across a few instances of macho posturing where people presented solutions that only showed off their alleged brilliance instead of helping others. This includes a recursive solution to a problem that wasn’t even supposed to be solved via recursion. Others used Java functions that negated the purpose of the exercises. I saw one guy posting what he thought to be oh-so smart one-liners. Of course, one could use String.replace() to replace characters in a string, but if you’re supposed to practice loops, you’re only cheating yourself.
I won’t claim that my solutions are the “best” out there. Yet, I do think that my code is well written. I have also made sure to only use the Java functions mentioned on the CodingBat website. CodingBat contains 13 section on Java, with some sections containing up to 30 exercises. Therefore, I will split my solutions over a long series of posts.