CHAPTER 7: Arrays and ArrayLists
ellipsis(...)
A(n) __________ in the parameter list of a method indicates that the method can receive a variable number of arguments.
variables
An array is a group of __________ (called elements or components) containing values that all have the same type.
type
An array is a group of variables containing values that all have the same __________ .
two-dimensional
An array that uses two indices is referred to as a(n) __________ array.
an array of Strings, called args by convention
Command-line arguments are stored in __________ .
for(int i = 0; i < b.length; i++)
Find and correct the error for the following program segments: Assume int[ ] b= new int[ 10 ]; for ( int i=0; i <= b.length; i++ ) b[i]= 1;
final int ARRAY_SIZE = 10; (OR final in ARRAY_SIZE = 5; int myArraySize = 10;)
Find and correct the error for the following program segments: final int ARRAY_SIZE = 5; ARRAY_SIZE = 10;
Nine
How many elements does the array table[ ARRAY_SIZE][ARRAY_SIZE ] contain (ARRAY_SIZE = 3)?
arrays
Lists and tables of values can be stored in __________ .
fractions[ 9 ]=1.667;
Perform the following task for an array called fractions: Assign the value 1.667 to array element 9.
fractions[ 6 ]=3.333;
Perform the following task for an array called fractions: Assign the value 3.333 to array element 6.
final int ARRAY_SIZE = 10;
Perform the following task for an array called fractions: Declare a constant ARRAY_SIZE that's initialized to 10.
double[] fractions =new double[ ARRAY_SIZE ];
Perform the following task for an array called fractions: Declare an array with ARRAY_SIZE elements of type double, and initialize the elements to 0.
fractions[ 4 ];
Perform the following task for an array called fractions: Refer to array element 4.
double total =0.0; for ( int x=0; x < fractions.length; x++ ) total += fractions[ x ];
Perform the following task for an array called fractions: Sum all the elements of the array, using a for statement.
int[][] table =new int[ ARRAY_SIZE ][ ARRAY_SIZE ];
Perform the following task for an array called table: Declare and create the array as an integer array that has three rows and three columns. Assume that the constant ARRAY_ SIZE has been declared to be 3.
for ( int x=0; x < table.length; x++ ) for ( int y=0; y < table[ x ].length; y++ ) table[ x][y]=x+y;
Perform the following task for an array called table: Use a for statement to initialize each element of the array to the sum of its indices. Assume that the integer variables x and y are declared as control variables.
index (or subscript or position number)
The number used to refer to a particular array element is called the element's __________.
false
True/False: An array can store many different types of values.
false
True/False: An array index should normally be of type float.
false
True/False: Arrays are only designed to hold primitive data types and Strings.
true
True/False: Arrays that require two indices to identify a particular element are called two- dimensional arrays.
false
True/False: Command-line arguments are separated by commas.
true
True/False: Constant variables must be initialized before they are used and cannot be modified thereafter.
false
True/False: Histograms provide the history of how an array is used in a Java program.
false
True/False: In reference to the array frequency, the expression ++frequency[0] copies the value from cell 0 of the array to cell 1.
false
True/False: Multidimensional arrays cannot be initialized in declarations like a one- dimensional array.
false
True/False: Only literal integer values can be used as an index into an array.
false
True/False: The number of elements in an array is specified in the square brackets after the array name in a declaration.
false
True/False: The position number in parentheses is formally called an index.
false
True/False: The type of the parameter in an enhanced for statement must be an int.
true
True/False: Using arrays can be an elegant way to avoid using sets of counter variables and switch statements.
true
True/False: When an array is passed to a method, any changes made to the array elements in the method are actually made to the original array object in memory.
false
True/False: When initializing the elements of an array using a for statement, the value of the element must be the value of the counter.
args.length.i
Use the expression __________ to receive the total number of arguments in a command line. Assume that command-line arguments are stored in String[] args.