622
c. We can use nestedforloops to sum the values in each column of the array
plan. What range of values would the outerforloop count through to do
this? (pp. 588–589)
d.Write a code fragment that initializes the array planto all 1s. (pp. 589–590)
e.Write a code fragment that prints the contents of the array plan, one row per
line of output. (pp. 589–590)
3.Suppose the array planis passed as an argument to a method in which the cor-
responding parameter is named someArray. What would the declaration of
someArraylook like in the parameter list? (p. 590)
4.Given the declarations
final intSIZE = 10 ;
char[][][][] quick = new char[SIZE][SIZE][SIZE][SIZE- 1 ];
a.How many components does the array quickcontain? (pp. 591–592)
b.Write a code fragment that fills the array quickwith blanks. (pp. 591–592)
5.Why is it inappropriate to use a variable of a floating-point type as a loop con-
trol variable? (pp. 595–596)
6.If a computer has four digits of precision, what would be the result of the
following addition operation? (pp. 595–596)
400400.000 + 199.9
7.Given that the pattern "$#,##0.00"has been stored into the object referenced
by the DecimalFormatvariable num, what is the result of each of the following
calls to format? (pp. 602–604)
num.format(39144932.109)
num.format(–27.0)
8.What pattern would you use to display a numerical value as a percentage with
three leading blanks, at least one digit in the integer part, and exactly two frac-
tional digits? (pp. 602–604)
Answers
- float[][] plan;
plan = new float[ 30 ][ 10 ]; - a.plan[ 13 ][ 7 ] = 27.3;
b. for(row = 0 ; row < 30 ; row++)
c. for(col = 0 ; col < 10 ; col++)
d.for(row = 0 ; row < 30 ; row++)
for(col = 0 ; col < 10 ; col++)
plan[row][col] = 1.0;
e. for(row = 0 ; row < 30 ; row++)
{
for(col = 0 ; col < 10 ; col++)
outFile.print(plan[row][col]);
outFile.println();
}