Programming and Problem Solving with Java

(やまだぃちぅ) #1

514


6.Given the declarations in Question 2 and the following code fragment, which reads
characters into the arrayfirstNameuntil a blank is encountered, write afor
statement that prints out the portion of the array that is filled with input data. (p.
000)
n = 0 ;
line = infile.readLine();
letter = line.charAt(n);
while(letter != ' ')
{
firstName[n] = letter;
n++;
letter = line.charAt(n);
}

Answers
1.boolean[] quizAnswer = new boolean[ 12 ];


  1. a. firstName[ 0 ] = 'A';b.outFile.println(firstName[ 13 ]);
    c. for(intindex = 0 ; index < firstName.length; index++)
    firstName[index] = ' ';
    3.int[] oddNums = { 1 , 3 , 5 , 7 , 9 };
    4.public voidsomeFunc(float[] values)

  2. a. gradeBook[ 9 ].gpa = 3.25;b.gradeBook[ 3 ].examScores[ 2 ] = 78 ;
    6.for(intindex = 0 ; index < n; index++)
    outFile.print(firstName[index]);


Exam Preparation Exercises


1.Every component in an array must have the same type, and the number of
components is fixed at creation time. (True or False?)
2.The components of an array must be of a primitive type. (True or False?)
3.Declare and instantiate one-dimensional arrays according to the following de-
scriptions.
a.A 24-element floatarray
b.A 500-element intarray
c. A 50-element double-precision floating-point array
d.A 10-element chararray
4.Write a code fragment to perform the following tasks:
a.Declare a constant namedCLASS_SIZErepresenting the number of
Free download pdf