Page 458 - Introduction to Programming with Java: A Problem Solving Approach
P. 458
424 Chapter 10 Arrays and ArrayLists Review Questions
§10.2 Array Basics
1. It’s legal to store ints and also doubles in a single standard array. (T / F)
2. Given an array that’s named myArray, you access the first element in the array using myArray[0]. (T / F)
§10.3 Array Declaration and Creation
3. Provide a declaration for an array of strings called names.
4. Consider the heading for any main method:
public static void main(String[] args)
What kind of a thing is args?
5. Suppose you create an array with the statement:
char[] choices = new char[4];
What is the default value in a typical element of this array? Is it garbage or something in particular?
§10.4 Array length Property and Partially Filled Arrays
6. The value of an array’s length equals the value of the array’s largest acceptable index. (T / F)
§10.5 Copying an Array
7. Given
String letters = "abcdefghijklmnopqrstuvwxyz";
char alphabet[] = new char[26];
Write a for loop that initializes alphabet with the characters in letters.
8. Write a single statement that copies all the elements in
char arr1[] = {'x', 'y', 'z'};
to the last three elements of
char arr2[] = new char[26];
§10.6 Problem Solving with Array Case Studies
9. In Figure 10.7’s MovingAverage program, suppose you want to shift in the other direction. How would you
write the inner for loop header, and how would you write the array assignment statement in the inner for
loop?
10. What kind of value does a typical histogram “bin” contain?
§10.7 Searching an Array
11. It’s possible to search array ids for an element equal to id with nothing more than this:
int i;
Apago PDF Enhancer
for (i=0; i<ids.length && id != ids[i]; i++)
{}
if (<boolean-expression>) {
return i;
}
What is the <boolean-expression> that indicates that i has been found?