Your browser has JavaScript turned off. This page is best viewed with Javascript enabled. Certain functions on this site will not work, and some style sheets will not load. Check your browser preferences to enable JavaScript.

Teach Yourself Java

Lesson 5 Quiz

1. Individual Arrays can hold
One type of variable
Two types of variables
Infinite types of variables
None of the above

2. T/F: To get to the fifth element in an array, you have to go through the first four.
True
False

3. T/F: In Java, Arrays can be expanded and contracted whenever you want.
True
False

4. The following code will make which array?

String[] tracks;
tracks = new String[4];
tracks[1] = "here";
tracks[3] = "there";

(null indicates that there is no element in that index)
here, null, there, null.
null, here, there, null
null, null, here, there
null, here, null, there

5. In a array nums of ints with the following values: 2, 4, 1, 0, 6, 7, what does the following statements change the array to be?

nums[1] = nums[5] + 6;
nums[0]++;
nums[5] = nums[1] – 6;
2, 12, 1, 0, 6, 7
12, 4, 1, 0, 0, 7
3, 13, 1, 0, 6, 7
13, 4, 1, 0, 13, 1

6. What does the following loop change the array “grades” to be if grades starts out as
81, 67, 98, 93, 94, 83?

for (int k = 0; k < 6; k++)
{
    if (grades[k] < 90)
    {
       grades[k] += 5;
    }
    else
    {
       grades[k] += 2;
    }
}
86, 72, 103, 98, 99, 88
83, 69, 103, 98, 99, 85
81, 67, 100, 95, 96, 83
86, 72, 100, 95, 96, 88