Chapter 4. Discovering Loops and Methods
In this chapter, we will learn how to repeatedly execute portions of our code in a controlled and precise way by looking at different types of loops in Java. These include while
loops, do-while
loops, and for
loops. We will learn about the best occasions to use the different types of loops.
Then we will briefly cover the topic of random numbers. We will also see how the Java Random
class can be used. This will obviously be of great help in enhancing our math game.
Next, we will look at methods. They allow us to compartmentalize our code into more manageable blocks. We will then see how to share data between methods and divide programming tasks to simplify problems.
We will then use all that we have learned about loops, random numbers and methods on our math game project. For example, we will make the game change the question after each time we attempt the answer.
We will also add question difficulty levels and random questions within a range...