Chapter 13
Using Arrays to Juggle Values
IN THIS CHAPTER
Dealing with several values at a time
Writing to disk files
Running a program with different values each time
Welcome to the Java Motel! No haughty bellhops, no overpriced room service, none of the silly jokes that I write in other chapters. Just a nice room at a darn good price!
Getting Your Ducks All in a Row
The Java Motel, with its ten comfortable rooms, sits in a quiet place off the main highway. Aside from a small, separate office, the motel is just one long row of ground-floor rooms. Each room is easily accessible from the spacious front parking lot.
Oddly enough, the motel’s rooms are numbered 0 through 9. I could say that the numbering is a fluke — something to do with the builder’s original design plan. But the truth is that starting with 0 makes the examples in this chapter easier to write. Computer programming structures start counting from 0 onward. That's all there is to it.
Anyway, you’re trying to keep track of the number of guests in each room. To store all the numbers, you use an array.
An array is a row of values, like the row of rooms in a 1-floor motel. To picture the array, look at the Java Motel in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access