Deck 7: Arrays and the Arraylist Class

Full screen (f)
exit full mode
Question
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
Use Space or
up arrow
down arrow
to flip the card.
Question
Objects in an array are accessed with subscripts, just like any other data type in an array.
Question
By default, Java initializes array elements to __________.

A) 0
B) 100
C) -1
D) 1
Question
Any items typed on the command line, separated by a space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
Question
Each array in Java has a public field named __________ that contains the number of elements in the array..

A) size
B) capacity
C) length
D) limit
Question
The ___________ method is used to insert an item into an ArrayList.

A) insert
B) add
C) store
D) putItem
Question
Subscripting always starts with __________.

A) 0
B) 1
C) -1
D) none of these
Question
The String [ ] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
Question
An ArrayList object automatically expands in size to accommodate the items stored in it.
Question
When an array of objects is declared but not initialized, the array values are set to null.
Question
If a[ ] and b[ ] are two integer arrays, the expression a == b compares the array contents.
Question
It is common practice to use a __________ variable as a size declarator.

A) static
B) reference
C) final
D) boolean
Question
Java limits the number of dimensions that an array can have to 15.
Question
An array can hold multiple values of several different types of data simultaneously.
Question
A sorting algorithm is used to locate a specific item in a larger collection of data.
Question
Once an array is created, its size cannot be changed.
Question
Declaring an array reference variable does not create an array.
Question
To determine if two arrays are equal you must compare each of the elements of the two arrays.
Question
Java does not limit the number of dimensions an array may have.
Question
The __________ indicates the number of elements the array can hold.

A) new operator
B) array's size declarator
C) array's data type
D) version of Java
Question
Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passMyArray(int[1, 2])
B) public static void passMyArray(int[ ][ ])
C) public static void passMyArray[1][2])
D) public static void passMyArray(int[ ],int[ ] myArray)
Question
To return an array of long values from a method, which return type should be used for the method?

A) long[ARRAY_SIZE]
B) array
C) long[ ]
D) long
Question
A(n) __________ is used as an index to pinpoint a specific element within an array.

A) boolean value
B) element
C) argument
D) subscript
Question
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?

A) set
B) store
C) add
D) insert
Question
When an individual element of an array is passed to a method __________.

A) a reference to the array is passed
B) it is passed like any other variable
C) the method does not have access to the original array
D) All of these are true.
Question
Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

A) active array sequencing
B) array bounds checking
C) scope resolution binding
D) buffer overrun protection
Question
When an array is passed to a method __________.

A) it is passed just as any other object would be passed
B) the method has direct access to the original array
C) a reference to the array is passed
D) All of these are true
Question
In memory, an array of String objects __________.

A) consists of elements, each of which is a reference to a String object
B) is compressed to four bytes for each element
C) must be initialized when the array is declared
D) consists of an array of references to String objects
Question
A ragged array is __________.

A) a two-dimensional array where the rows have different numbers of columns
B) a one-dimensional array for which the number of elements is unknown
C) a two-dimensional array for which the number of rows is unknown
D) a partially initialized two-dimensional array of ranged values
Question
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

A) numbers.length
B) numbers.length[r]
C) numbers[r].length
D) numbers[r].length[r]
Question
You can use the __________ method to replace an item at a specific location in an ArrayList.

A) set
B) remove
C) replace
D) add
Question
The binary search algorithm __________.

A) is less efficient than the sequential search algorithm
B) will cut the portion of the array being searched in half each time it fails to locate the search value
C) will have a maximum number of comparisons equal to the number of elements in the array
D) will, normally, have the number of comparisons that is half the number of elements in the array
Question
In Java, you do not use the new operator when you use a(n) ____________.

A) array size declarator
B) initialization list
C) two-dimensional array
D) any of these
Question
A partially filled array is normally used __________.

A) when only a very small number of values need to be stored
B) when you know how many elements will be in the array but not what the values are
C) with an accompanying parallel array
D) with an accompanying integer value that holds the number of items stored in the array
Question
A search algorithm __________.

A) arranges elements in ascending order
B) arranges elements in descending order
C) is used to locate a specific item in a collection of data
D) is rarely used with arrays
Question
In order to do a binary search on an array __________.

A) the array must first be sorted
B) you must first do a sequential search to be sure the element you are looking for is there
C) the values of the array must be numeric
D) no requirements are necessary
Question
The ArrayList class is in the __________ package.

A) java.arraylist
B) java.lang
C) java.array
D) java.util
Question
Which of the following is a valid declaration for a ragged array with five rows but no columns?

A) int[ ][ ] ragged = new int[5];
B) int[ ][ ] ragged = new int[ ][5];
C) int[ ][ ] ragged = new int[5][ ];
D) int[ ] ragged = new int[5];
Question
The sequential search algorithm __________.

A) returns 1 if the value being searched for is found or -1 if the value is not found
B) requires the array to be ascending order
C) uses a loop to sequentially step through an array, starting with the first element
D) must always be implemented as a method
Question
The __________ method removes an item from an ArrayList at a specific index.

A) remove
B) pop
C) deleteAt
D) clear
Question
Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passArray(int[1,2])
B) public static void passArray(int [ ][ ])
C) public static void passArray(int[1],[2])
D) public static void passArray(int[ ], int[ ])
Question
What is the value of scores[2][3] in the following array?
int[ ][ ] scores = { {88, 80, 79, 92}, {75, 84, 93, 80},
{98, 95, 92, 94}, {91, 84, 88, 96} };

A) 95
B) 84
C) 94
D) 93
Question
What would be the result after the following code is executed?
int[ ] x = {23, 55, 83, 19};
Int[ ] y = {36, 78, 12, 24};
X = y;
Y = x;

A) x[ ] = {36, 78, 12, 24} and y[ ] = {23, 55, 83, 19}
B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24}
C) x[ ] = {23, 55, 83, 19} and y[ ] = {23, 55, 83, 19}
D) Nothing. This is a compile error.
Question
What will be the value of x[8] after the following code is executed?
final int SUB = 12;
Int[ ] x = new int[SUB];
Int y = 20;
For(int i = 0; i < SUB; i++)
{
X[i] = y;
Y += 5;
}

A) 50
B) 55
C) 60
D) 65
Question
What would be the result of executing the following code?
int[ ] x = {0, 1, 2, 3, 4, 5};

A) An array of 6 values, all initialized to 0 and referenced by the variable x will be created.
B) An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.
C) The variable x will contain the values 0 through 5.
D) A compiler error will occur.
Question
What would be the result after the following code is executed?
final int SIZE = 25;
Int[ ] array1 = new int[SIZE];
).. // Code that will put values in array1
Int value = 0;
For (int a = 0; a < array1.length; a++)
{
Value += array1[a];
}

A) value contains the highest value in array1.
B) value contains the lowest value in array1.
C) value contains the sum of all the values in array1.
D) This code would cause the program to crash.
Question
What would be the result after the following code is executed? int[ ] numbers = {50, 10, 15, 20, 25, 100, 30};
Int value = 0;
For (int i = 1; i < numbers.length; i++)
Value += numbers[i];

A) The value variable will contain the average of all the values in the numbers array.
B) The value variable will contain the sum of all the values in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the highest value in the numbers array.
Question
What will be the result after the following code is executed?
final int ARRAY_SIZE = 5;
Float[ ] x = float[ARRAY_SIZE];
For (i = 1; i <= ARRAY_SIZE; i++)
{
X[i] = 10.0;
}

A) A runtime error will occur.
B) All the values in the array will be initialized to 10.0.
C) All the values in the array except the first will be set to 10.0.
D) The code contains a syntax error and will not compile.
Question
Given the following two-dimensional array declaration, which statement is true?
int[ ][ ] numbers = new int[6][9];

A) The numbers array has 54 rows.
B) The numbers array has 15 rows.
C) The numbers array has 6 rows and 9 columns.
D) The numbers array has 6 columns and 9 rows.
Question
For the following code, what would be the value of str[2]?
String[ ] str = {"abc", "def", "ghi", "jkl"};

A) a reference to the String object containing "ghi"
B) "ghi"
C) a reference to the String object containing "def"
D) "def"
Question
What will be the results after the following code is executed?
int[ ] array1 = new int[25];
).. // Code that will put values in array1
Int value = array1[0];
For (int a = 1; a < array1.length; a++)
{
If (array1[a] < value)
Value = array1[a];
}

A) value contains the highest value in array1
B) value contains the lowest value in array1
C) value contains the sum of all the values in array1
D) value contains the average of all the values in array1
Question
What would be the result after the following code is executed?
int[ ] numbers = {40, 3, 5, 7, 8, 12, 10};
Int value = numbers[0];
For (int i = 1; i < numbers.length; i++)
{
If (numbers[i] < value)
Value = numbers[i];
}

A) The value variable will contain the average of all the values in the numbers array.
B) The value variable will contain the sum of all the values in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the highest value in the numbers array.
Question
If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

A) for (int row = 1; row < numbers.length; row++)
{
For (int col = 1; col < numbers.length; col++)
Total += numbers[row][col];
}
B) for (int row = 0; row < numbers.length; row++)
{
For (int col = 0; col < numbers.length; col++)
Total += numbers[row][col];
}
C) for (int row = 0; row < numbers[row].length; row++)
{
For (int col = 0; col < numbers.length; col++)
Total += numbers[row][col];
}
D) for (int row = 0; row < numbers.length; row++)
{
For (int col = 0; col < numbers[row].length; col++)
Total += numbers[row][col];
}
Question
Which of the following for loops is valid, given the following declaration?
String[ ] names = {"abc", "def", "ghi", "jkl"};

A) for (int i = 0; i < names.length; i++)
System.out.println(names[i].length);
B) for (int i = 0; i < names.length(); i++)
System.out.println(names[i].length);
C) for (int i = 0; i < names.length; i++)
System.out.println(names[i].length());
D) for (int i = 0; i < names.length(); i++)
System.out.println(names[i].length());
Question
If final int SIZE = 15 and int[ ] x = new int[SIZE], what would be the range of subscript values that could be used with x[ ]?

A) 1 through 15
B) 1 through 14
C) 0 through 14
D) 0 through 15
Question
Given that String[ ] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement.

A) str.uppercase();
B) str[0].upperCase();
C) str.toUpperCase();
D) str[0].toUpperCase();
Question
What will be the value of x[8] after the following code is executed?
final int SUB = 12;
Int[ ] x = new int[SUB];
Int y = 100;
For(int i = 0; i < SUB; i++)
{
X[i] = y;
Y += 10;
}

A) 170
B) 180
C) 190
D) 200
Question
What will be the results after the following code is executed?
int[ ] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 };
Int a = 10;
If(x[2] > x[5])
A = 5;
Else
A = 8;

A) a = 5
B) a = 8
C) a = 10
D) a = 13
Question
What would be the result after the following code is executed?
int[ ] x = {23, 55, 83, 19};
Int[ ] y = {36, 78, 12, 24};
For(int a = 0; a < x.length; a++)
{
X[a] = y[a];
Y[a] = x[a];
}

A) x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19}
B) x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
C) x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19}
D) Nothing. This is a compile error.
Question
What would be the result after the following code is executed?
final int SIZE = 25;
Int[ ] array1 = new int[SIZE];
).. // Code that will put values in array1
Int value = 0;
For (int a = 0; a <= array1.length; a++)
{
Value += array1[a];
}

A) value contains the highest value in array1.
B) value contains the lowest value in array1.
C) value contains the sum of all the values in array1.
D) This code would cause the program to crash.
Question
What does the following statement do? double[ ] array1 = new double[10];

A) It declares array1 to be a reference to an array of double values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten double values.
D) It does all of these.
Question
What does specify in the following statement? ArrayList nameList = new ArrayList();

A) It specifies that String objects may not be stored in the ArrayList object.
B) It specifies that everything stored in the ArrayList object will be converted to a String object.
C) It specifies that only String objects may be stored in the ArrayList object.
D) It specifies that the ArrayList will be converted to a String array.
Question
Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10;
Long[ ] array1 = new long[ARRAY_SIZE];

A) It declares array1 to be a reference to an array of long values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten long values.
D) It will allow valid subscripts in the range of 1 through 10.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/63
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 7: Arrays and the Arraylist Class
1
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
True
2
Objects in an array are accessed with subscripts, just like any other data type in an array.
True
3
By default, Java initializes array elements to __________.

A) 0
B) 100
C) -1
D) 1
A
4
Any items typed on the command line, separated by a space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
5
Each array in Java has a public field named __________ that contains the number of elements in the array..

A) size
B) capacity
C) length
D) limit
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
6
The ___________ method is used to insert an item into an ArrayList.

A) insert
B) add
C) store
D) putItem
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
7
Subscripting always starts with __________.

A) 0
B) 1
C) -1
D) none of these
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
8
The String [ ] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
9
An ArrayList object automatically expands in size to accommodate the items stored in it.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
10
When an array of objects is declared but not initialized, the array values are set to null.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
11
If a[ ] and b[ ] are two integer arrays, the expression a == b compares the array contents.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
12
It is common practice to use a __________ variable as a size declarator.

A) static
B) reference
C) final
D) boolean
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
13
Java limits the number of dimensions that an array can have to 15.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
14
An array can hold multiple values of several different types of data simultaneously.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
15
A sorting algorithm is used to locate a specific item in a larger collection of data.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
16
Once an array is created, its size cannot be changed.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
17
Declaring an array reference variable does not create an array.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
18
To determine if two arrays are equal you must compare each of the elements of the two arrays.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
19
Java does not limit the number of dimensions an array may have.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
20
The __________ indicates the number of elements the array can hold.

A) new operator
B) array's size declarator
C) array's data type
D) version of Java
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passMyArray(int[1, 2])
B) public static void passMyArray(int[ ][ ])
C) public static void passMyArray[1][2])
D) public static void passMyArray(int[ ],int[ ] myArray)
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
22
To return an array of long values from a method, which return type should be used for the method?

A) long[ARRAY_SIZE]
B) array
C) long[ ]
D) long
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) __________ is used as an index to pinpoint a specific element within an array.

A) boolean value
B) element
C) argument
D) subscript
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?

A) set
B) store
C) add
D) insert
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
25
When an individual element of an array is passed to a method __________.

A) a reference to the array is passed
B) it is passed like any other variable
C) the method does not have access to the original array
D) All of these are true.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
26
Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

A) active array sequencing
B) array bounds checking
C) scope resolution binding
D) buffer overrun protection
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
27
When an array is passed to a method __________.

A) it is passed just as any other object would be passed
B) the method has direct access to the original array
C) a reference to the array is passed
D) All of these are true
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
28
In memory, an array of String objects __________.

A) consists of elements, each of which is a reference to a String object
B) is compressed to four bytes for each element
C) must be initialized when the array is declared
D) consists of an array of references to String objects
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
29
A ragged array is __________.

A) a two-dimensional array where the rows have different numbers of columns
B) a one-dimensional array for which the number of elements is unknown
C) a two-dimensional array for which the number of rows is unknown
D) a partially initialized two-dimensional array of ranged values
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
30
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

A) numbers.length
B) numbers.length[r]
C) numbers[r].length
D) numbers[r].length[r]
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
31
You can use the __________ method to replace an item at a specific location in an ArrayList.

A) set
B) remove
C) replace
D) add
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
32
The binary search algorithm __________.

A) is less efficient than the sequential search algorithm
B) will cut the portion of the array being searched in half each time it fails to locate the search value
C) will have a maximum number of comparisons equal to the number of elements in the array
D) will, normally, have the number of comparisons that is half the number of elements in the array
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
33
In Java, you do not use the new operator when you use a(n) ____________.

A) array size declarator
B) initialization list
C) two-dimensional array
D) any of these
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
34
A partially filled array is normally used __________.

A) when only a very small number of values need to be stored
B) when you know how many elements will be in the array but not what the values are
C) with an accompanying parallel array
D) with an accompanying integer value that holds the number of items stored in the array
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
35
A search algorithm __________.

A) arranges elements in ascending order
B) arranges elements in descending order
C) is used to locate a specific item in a collection of data
D) is rarely used with arrays
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
36
In order to do a binary search on an array __________.

A) the array must first be sorted
B) you must first do a sequential search to be sure the element you are looking for is there
C) the values of the array must be numeric
D) no requirements are necessary
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
37
The ArrayList class is in the __________ package.

A) java.arraylist
B) java.lang
C) java.array
D) java.util
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following is a valid declaration for a ragged array with five rows but no columns?

A) int[ ][ ] ragged = new int[5];
B) int[ ][ ] ragged = new int[ ][5];
C) int[ ][ ] ragged = new int[5][ ];
D) int[ ] ragged = new int[5];
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
39
The sequential search algorithm __________.

A) returns 1 if the value being searched for is found or -1 if the value is not found
B) requires the array to be ascending order
C) uses a loop to sequentially step through an array, starting with the first element
D) must always be implemented as a method
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
40
The __________ method removes an item from an ArrayList at a specific index.

A) remove
B) pop
C) deleteAt
D) clear
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passArray(int[1,2])
B) public static void passArray(int [ ][ ])
C) public static void passArray(int[1],[2])
D) public static void passArray(int[ ], int[ ])
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
42
What is the value of scores[2][3] in the following array?
int[ ][ ] scores = { {88, 80, 79, 92}, {75, 84, 93, 80},
{98, 95, 92, 94}, {91, 84, 88, 96} };

A) 95
B) 84
C) 94
D) 93
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
43
What would be the result after the following code is executed?
int[ ] x = {23, 55, 83, 19};
Int[ ] y = {36, 78, 12, 24};
X = y;
Y = x;

A) x[ ] = {36, 78, 12, 24} and y[ ] = {23, 55, 83, 19}
B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24}
C) x[ ] = {23, 55, 83, 19} and y[ ] = {23, 55, 83, 19}
D) Nothing. This is a compile error.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
44
What will be the value of x[8] after the following code is executed?
final int SUB = 12;
Int[ ] x = new int[SUB];
Int y = 20;
For(int i = 0; i < SUB; i++)
{
X[i] = y;
Y += 5;
}

A) 50
B) 55
C) 60
D) 65
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
45
What would be the result of executing the following code?
int[ ] x = {0, 1, 2, 3, 4, 5};

A) An array of 6 values, all initialized to 0 and referenced by the variable x will be created.
B) An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.
C) The variable x will contain the values 0 through 5.
D) A compiler error will occur.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
46
What would be the result after the following code is executed?
final int SIZE = 25;
Int[ ] array1 = new int[SIZE];
).. // Code that will put values in array1
Int value = 0;
For (int a = 0; a < array1.length; a++)
{
Value += array1[a];
}

A) value contains the highest value in array1.
B) value contains the lowest value in array1.
C) value contains the sum of all the values in array1.
D) This code would cause the program to crash.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
47
What would be the result after the following code is executed? int[ ] numbers = {50, 10, 15, 20, 25, 100, 30};
Int value = 0;
For (int i = 1; i < numbers.length; i++)
Value += numbers[i];

A) The value variable will contain the average of all the values in the numbers array.
B) The value variable will contain the sum of all the values in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the highest value in the numbers array.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
48
What will be the result after the following code is executed?
final int ARRAY_SIZE = 5;
Float[ ] x = float[ARRAY_SIZE];
For (i = 1; i <= ARRAY_SIZE; i++)
{
X[i] = 10.0;
}

A) A runtime error will occur.
B) All the values in the array will be initialized to 10.0.
C) All the values in the array except the first will be set to 10.0.
D) The code contains a syntax error and will not compile.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
49
Given the following two-dimensional array declaration, which statement is true?
int[ ][ ] numbers = new int[6][9];

A) The numbers array has 54 rows.
B) The numbers array has 15 rows.
C) The numbers array has 6 rows and 9 columns.
D) The numbers array has 6 columns and 9 rows.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
50
For the following code, what would be the value of str[2]?
String[ ] str = {"abc", "def", "ghi", "jkl"};

A) a reference to the String object containing "ghi"
B) "ghi"
C) a reference to the String object containing "def"
D) "def"
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
51
What will be the results after the following code is executed?
int[ ] array1 = new int[25];
).. // Code that will put values in array1
Int value = array1[0];
For (int a = 1; a < array1.length; a++)
{
If (array1[a] < value)
Value = array1[a];
}

A) value contains the highest value in array1
B) value contains the lowest value in array1
C) value contains the sum of all the values in array1
D) value contains the average of all the values in array1
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
52
What would be the result after the following code is executed?
int[ ] numbers = {40, 3, 5, 7, 8, 12, 10};
Int value = numbers[0];
For (int i = 1; i < numbers.length; i++)
{
If (numbers[i] < value)
Value = numbers[i];
}

A) The value variable will contain the average of all the values in the numbers array.
B) The value variable will contain the sum of all the values in the numbers array.
C) The value variable will contain the lowest value in the numbers array.
D) The value variable will contain the highest value in the numbers array.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
53
If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

A) for (int row = 1; row < numbers.length; row++)
{
For (int col = 1; col < numbers.length; col++)
Total += numbers[row][col];
}
B) for (int row = 0; row < numbers.length; row++)
{
For (int col = 0; col < numbers.length; col++)
Total += numbers[row][col];
}
C) for (int row = 0; row < numbers[row].length; row++)
{
For (int col = 0; col < numbers.length; col++)
Total += numbers[row][col];
}
D) for (int row = 0; row < numbers.length; row++)
{
For (int col = 0; col < numbers[row].length; col++)
Total += numbers[row][col];
}
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
54
Which of the following for loops is valid, given the following declaration?
String[ ] names = {"abc", "def", "ghi", "jkl"};

A) for (int i = 0; i < names.length; i++)
System.out.println(names[i].length);
B) for (int i = 0; i < names.length(); i++)
System.out.println(names[i].length);
C) for (int i = 0; i < names.length; i++)
System.out.println(names[i].length());
D) for (int i = 0; i < names.length(); i++)
System.out.println(names[i].length());
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
55
If final int SIZE = 15 and int[ ] x = new int[SIZE], what would be the range of subscript values that could be used with x[ ]?

A) 1 through 15
B) 1 through 14
C) 0 through 14
D) 0 through 15
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
56
Given that String[ ] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement.

A) str.uppercase();
B) str[0].upperCase();
C) str.toUpperCase();
D) str[0].toUpperCase();
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
57
What will be the value of x[8] after the following code is executed?
final int SUB = 12;
Int[ ] x = new int[SUB];
Int y = 100;
For(int i = 0; i < SUB; i++)
{
X[i] = y;
Y += 10;
}

A) 170
B) 180
C) 190
D) 200
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
58
What will be the results after the following code is executed?
int[ ] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 };
Int a = 10;
If(x[2] > x[5])
A = 5;
Else
A = 8;

A) a = 5
B) a = 8
C) a = 10
D) a = 13
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
59
What would be the result after the following code is executed?
int[ ] x = {23, 55, 83, 19};
Int[ ] y = {36, 78, 12, 24};
For(int a = 0; a < x.length; a++)
{
X[a] = y[a];
Y[a] = x[a];
}

A) x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19}
B) x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
C) x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19}
D) Nothing. This is a compile error.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
60
What would be the result after the following code is executed?
final int SIZE = 25;
Int[ ] array1 = new int[SIZE];
).. // Code that will put values in array1
Int value = 0;
For (int a = 0; a <= array1.length; a++)
{
Value += array1[a];
}

A) value contains the highest value in array1.
B) value contains the lowest value in array1.
C) value contains the sum of all the values in array1.
D) This code would cause the program to crash.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
61
What does the following statement do? double[ ] array1 = new double[10];

A) It declares array1 to be a reference to an array of double values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten double values.
D) It does all of these.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
62
What does specify in the following statement? ArrayList nameList = new ArrayList();

A) It specifies that String objects may not be stored in the ArrayList object.
B) It specifies that everything stored in the ArrayList object will be converted to a String object.
C) It specifies that only String objects may be stored in the ArrayList object.
D) It specifies that the ArrayList will be converted to a String array.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
63
Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10;
Long[ ] array1 = new long[ARRAY_SIZE];

A) It declares array1 to be a reference to an array of long values.
B) It will allow valid subscripts in the range of 0 through 9.
C) It creates an instance of an array of ten long values.
D) It will allow valid subscripts in the range of 1 through 10.
Unlock Deck
Unlock for access to all 63 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 63 flashcards in this deck.