Java Reference
In-Depth Information
scores[0][1][0] refers to the multiple-choice score for the first student's second exam,
which is 9.0 . scores[0][1][1] refers to the essay score for the first student's second
exam, which is 22.5 . This is depicted in the following figure:
Which student
Which exam
Multiple-choice or essay
scores [i] [j] [k]
A multidimensional array is actually an array in which each element is another array. A three-
dimensional array consists of an array of two-dimensional arrays. A two-dimensional array
consists of an array of one-dimensional arrays. For example, suppose x = new int[2]
[2][5] , and x[0] and x[1] are two-dimensional arrays. X[0][0] , x[0][1] , x[1][0] ,
and x[1][1] are one-dimensional arrays and each contains five elements. x.length
isĀ  2 , x[0].length and x[1].length are 2 , and X[0][0].length , x[0][1].length ,
x[1][0].length , and x[1][1].length are 5 .
8.8.1 Case Study: Daily Temperature and Humidity
Suppose a meteorology station records the temperature and humidity every hour of every
day and stores the data for the past ten days in a text file named Weather.txt (see www
.cs.armstrong.edu/liang/data/Weather.txt ). Each line of the file consists of four numbers that
indicate the day, hour, temperature, and humidity. The contents of the file may look like
the one in (a).
Day
Temperature
Day
Temperature
Hour
Humidity
Hour
Humidity
1
1
76.4
0.92
10
24
98.7
0.74
1
2
77.7
0.93
1
2
77.7
0.93
. . .
10
. . .
10
23
97.7
0.71
23
97.7
0.71
10
24
98.7
0.74
1
1
76.4
0.92
(a)
(b)
Note that the lines in the file are not necessarily in increasing order of day and hour. For exam-
ple, the file may appear as shown in (b).
Your task is to write a program that calculates the average daily temperature and humid-
ity for the 10 days. You can use the input redirection to read the file and store the data in
a three-dimensional array named data . The first index of data ranges from 0 to 9 and
represents 10 days, the second index ranges from 0 to 23 and represents 24 hours, and the
third index ranges from 0 to 1 and represents temperature and humidity, as depicted in the
following figure:
Which day
Which hour
Temperature or humidity
data [ i ] [ j ] [ k ]
 
 
Search WWH ::




Custom Search