Published online by Cambridge University Press: 26 August 2009
OBJECTIVES
In this chapter you will study:
One-dimensional arrays;
Two-dimensional arrays;
Searching arrays; and
Passing arrays as arguments.
This chapter shows you how to work with arrays. You will learn how to define and manipulate both single and multidimensional arrays. In this chapter, as in others, we will develop real working programs to illustrate using Java arrays.
NOTES
COBOL uses the terms single-level table; Java uses one-dimensional array.
In keeping with the spirit of Java, here we will use array and dimension.
This chapter begins with the declaration and population of one-dimensional arrays, then illustrates how to declare and populate two-dimensional arrays. The examples use both numeric and string data values.
The chapter also describes how to search an array using Java and how to pass arrays as arguments to methods.
You will see that, although internally Java treats array processing somewhat differently than COBOL, Java array handling looks a lot like COBOL table processing to the programmer. Of course, we will continue to point out significant differences between Java and COBOL and the pitfalls to avoid when writing Java from a COBOL programmer's perspective.
This chapter assumes you understand the following:
COBOL:
Defining one & two level tables
Initializing one & two level tables
Table lookup techniques
Using subscripts and indexes
Perform-varying statement
Java:
OO concepts (Chapter 2)
Java program structure (Chapter 3)
Defining data (Chapter 4)
Decision making (Chapter 6)
Looping (Chapter 7)
DECLARING ONE-DIMENSIONAL ARRAYS
We begin our discussion of one-dimensional arrays by looking at loan processing for the Community National Bank (CNB).
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.