Java Reference
In-Depth Information
for ( int leg : legs)
{
sum += leg;
}
return ( double )sum/speed;
}
8.6 Two-Dimensional Arrays
SR 8.23 A multidimensional array is implemented in Java as an array of array
objects. The arrays that are elements of the outer array could also con-
tain arrays as elements. This nesting process could continue for as many
levels as needed.
SR 8.24 int high = scores[0][0];
int low = high;
for ( int row = 0; row < scores.length; row++)
for ( int col = 0; col < scores[row].length; col++)
{
if (scores[row][col] < low)
low = scores[row][col];
if (scores[row][col] > high)
high = scores[row][col];
}
System.out.println (high − low);
8.7 Polygons and Polylines
SR 8.25
A polyline is defined by a series of points that represent its vertices. The
drawPolyline method takes three parameters to specify its shape. The
first is an array of integers that represent the x coordinates of the points.
The second is an array of integers that represent the y coordinates of the
points. The third parameter is a single integer that indicates the number
of points to be used from the arrays.
SR 8.26
A polygon is always closed, whereas a polyline may be open. The first
and last coordinates of a polygon are automatically connected; that is
not the case for polylines.
SR 8.27
The results of the changes are:
a. The flame below the rocket is now solid red, because a polygon is
always closed and we specified it to be filled in.
b. The rocket ship's window disappears, because only the first two
points are used to draw the polygon, which results in an “invis-
ible” line being drawn instead of the window.
Search WWH ::




Custom Search