Java 6 Illuminated: An Active Learning Approach: An Active Learning Approach (Jones and Barlett Illuminated) by Anderson Julie & Franceschi Herve J

Java 6 Illuminated: An Active Learning Approach: An Active Learning Approach (Jones and Barlett Illuminated) by Anderson Julie & Franceschi Herve J

Author:Anderson, Julie & Franceschi, Herve J. [Anderson, Julie]
Language: eng
Format: mobi
Publisher: Jones & Bartlett Learning
Published: 2008-02-11T16:00:00+00:00


EXAMPLE 9.5 Processing a Column in a Two-Dimensional Array

At line 17, we declare and initialize a single-dimensional String array named familyMembers to make our prompt more user-friendly. At lines 24-28, we again use a do/while loop to prompt the user for a valid family member index.

To calculate the maximum value of the family member cell bills, we first initialize the variable memberMaxBill to the first element in the column (familyCellBills[0][currentMember]) at line 30. We then use a standard for loop at lines 31-39, following the pattern described earlier to update the value of memberMaxBill as necessary. There is one minor difference; we do not need to start the row at index 0 because we initialized memberMaxBill to the value of the element in row 0 of the column currentMember. Note that we assume that there is an element at column 0 of each row, that is, each row has been instantiated. The value of the variable memberMaxBill is then formatted and printed at lines 41-44. Figure 9.8 shows the output of the program.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.