Deck 6: Arrays

Full screen (f)
exit full mode
Question
The subscript of the first indexed variable in an array is:
(a)0
(b)1
(c)2
(d)3
Use Space or
up arrow
down arrow
to flip the card.
Question
The correct syntax for passing an array as an argument in a method is:
(a)a[]
(b)a()
(c)a
(d)a[0]..a[a.length]
Question
Java provides a looping mechanism for objects of a collection.This looping mechanism is called a __________ loop.
(a)While
(b)For
(c)For each
(d)All of the above
Question
A ________ loop is a good way to step through the elements of an array and perform some program action on each indexed variable.
(a)while
(b)do…while
(c)for
(d)all of the above
Question
A _________ can occur if a programmer allows an accessor method to return a reference to an array instance variable.
(a)short circuit
(b)privacy leak
(c)partially filled array
(d)syntax error
Question
A value of an enumerated type is similar to a/an:
(a)Instance variable
(b)Object of a class
(c)Named constant
(d)None of the above
Question
The correct syntax for accessing the length of an array named Numbers is:
(a)Numbers.length()
(b)Numbers.length
(c)both A and B
(d)none of the above
Question
An ArrayIndexOutOfBounds error is a:
(a)compiler error
(b)syntax error
(c)logic error
(d)all of the above
Question
An array has only one public instance variable,which is named length.
Question
An arrays length instance variables value can be changed by a program.
Question
What is the correct expression for accessing the 5th element in an array named colors?
(a)colors[3]
(b)colors[4]
(c)colors[5]
(d)colors[6]
Question
Which of the following initializer lists correctly initializes the indexed variables of an array named myDoubles?
(a)double myDoubles[double] = {0.0,1.0,1.5,2.0,2.5};
(b)double myDoubles[5] = new double(0.0,1.0,1.5,2.0,2.5);
(c)double[] myDoubles = {0.0,1.0,1.5,2.0,2.5};
(d)array myDoubles[double] = {0.0,1.0,1.5,2.0,2.5};
Question
The base type of an array may be all of the following but:
(a)string
(b)boolean
(c)long
(d)all of these may be a base type of an array.
Question
An array with more than one index is called a/an:
(a)partially filled array
(b)multidimensional array
(c)bidirectional array
(d)one dimensional array
Question
A type of array in which different rows can have different number of columns is called a/an:
(a)partially filled array
(b)ragged array
(c)initialized array
(d)none of the above
Question
An array is a collection of variables all of the same type.
Question
The name of the sorting algorithm that locates the smallest unsorted value in an array and places it in the next sorted position of the array is called:
(a)bubble sort
(b)merge sort
(c)radix sort
(d)selection sort
Question
Partially filled arrays require:
(a)a variable to track the number of array positions used
(b)the use of local variables
(c)the use of global variables
(d)all of the above
Question
Consider the following array:
What is the value of myArray[myArray[1] - myArray[0]]
(a)7
(b)9
(c)-3
(d)6
Question
The individual variables that together make up the array are referred to as:
(a)indexed variables
(b)subscripted variables
(c)elements of the array
(d)all of the above
Question
Declare and create an integer array that will contain the numbers 1 through 100.Use a for loop to initialize the indexed variables.
Question
Arrays are objects that are created with new just like class objects.
Question
In a vararg specification the ellipsis is not part of the Java syntax.
Question
Write a Java method that takes an integer array as a formal parameter and returns the sum of integers contained within the array.
Question
A one dimensional array is also called an array of arrays.
Question
Write a Java method as well as any facilitator methods needed to perform a sort on an array of whole numbers in descending order.
Question
You can only use array indexed variables as arguments to methods.
Question
What are three ways you can use the square brackets [ ] with an array name?
Question
A variable of an enumerated type can have the special value null.
Question
Explain what the main methods array parameter,args,is used for.
Question
A collection class is a class whose objects store a collection of values.
Question
You may cycle through elements of a collection object using a for loop.
Question
An array of chars is the same as a String in Java.
Question
Java allows you to declare arrays with more than one index.
Question
A method can not change the values stored in the indexed variables of an array argument.
Question
How are arrays tested to see if they contain the same contents?
Question
An array name references a memory address.
Question
Given the following character array
char[] h = {'H','E','L','L','O'};
Write a Java statement that will create a new String object from the character array.
Question
Discuss how you could represent a table of related records using a multidimensional array.
Question
Write a Java statement that declares and creates an array of Strings named Breeds.Your array should be large enough to hold the names of 100 dog breeds.
Question
Declare and create a 10 x 10 multidimensional array of doubles.
Question
Write Java statements to create a collection of integers,and to initialize each element of the collection to -1 using a for each statement.
Question
Initialize the array created in number 11 above to -1.0.
Question
What is the output of the following code?
int[] numbers = new int[10];
for(int i=0; i < numbers.length; ++i)
numbers[i] = i * 2;
for(int i=0; i < numbers.length; ++i)
System.out.print(numbers[i] + " ");
System.out.println();
Question
What is the output of the following code?
int[] numbers = new int[10];
for(int i=0; i < numbers.length; ++i)
numbers[i] = i * 2;
for(int i=0; i < numbers.length; ++i)
System.out.print(numbers[i] / 2 + " ");
System.out.println();
Question
Write a complete Java console application that prompts the user for a series of quiz scores.The user should type -1 to signify that the input of quiz scores is complete.Your program should then average the scores and display the result back to the user.
Question
Declare and create a multidimensional array to hold the first and last names of 10 people.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/47
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Arrays
1
The subscript of the first indexed variable in an array is:
(a)0
(b)1
(c)2
(d)3
A
2
The correct syntax for passing an array as an argument in a method is:
(a)a[]
(b)a()
(c)a
(d)a[0]..a[a.length]
C
3
Java provides a looping mechanism for objects of a collection.This looping mechanism is called a __________ loop.
(a)While
(b)For
(c)For each
(d)All of the above
C
4
A ________ loop is a good way to step through the elements of an array and perform some program action on each indexed variable.
(a)while
(b)do…while
(c)for
(d)all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
5
A _________ can occur if a programmer allows an accessor method to return a reference to an array instance variable.
(a)short circuit
(b)privacy leak
(c)partially filled array
(d)syntax error
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
6
A value of an enumerated type is similar to a/an:
(a)Instance variable
(b)Object of a class
(c)Named constant
(d)None of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
7
The correct syntax for accessing the length of an array named Numbers is:
(a)Numbers.length()
(b)Numbers.length
(c)both A and B
(d)none of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
8
An ArrayIndexOutOfBounds error is a:
(a)compiler error
(b)syntax error
(c)logic error
(d)all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
9
An array has only one public instance variable,which is named length.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
10
An arrays length instance variables value can be changed by a program.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
11
What is the correct expression for accessing the 5th element in an array named colors?
(a)colors[3]
(b)colors[4]
(c)colors[5]
(d)colors[6]
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following initializer lists correctly initializes the indexed variables of an array named myDoubles?
(a)double myDoubles[double] = {0.0,1.0,1.5,2.0,2.5};
(b)double myDoubles[5] = new double(0.0,1.0,1.5,2.0,2.5);
(c)double[] myDoubles = {0.0,1.0,1.5,2.0,2.5};
(d)array myDoubles[double] = {0.0,1.0,1.5,2.0,2.5};
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
13
The base type of an array may be all of the following but:
(a)string
(b)boolean
(c)long
(d)all of these may be a base type of an array.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
14
An array with more than one index is called a/an:
(a)partially filled array
(b)multidimensional array
(c)bidirectional array
(d)one dimensional array
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
15
A type of array in which different rows can have different number of columns is called a/an:
(a)partially filled array
(b)ragged array
(c)initialized array
(d)none of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
16
An array is a collection of variables all of the same type.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
17
The name of the sorting algorithm that locates the smallest unsorted value in an array and places it in the next sorted position of the array is called:
(a)bubble sort
(b)merge sort
(c)radix sort
(d)selection sort
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
18
Partially filled arrays require:
(a)a variable to track the number of array positions used
(b)the use of local variables
(c)the use of global variables
(d)all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
19
Consider the following array:
What is the value of myArray[myArray[1] - myArray[0]]
(a)7
(b)9
(c)-3
(d)6
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
20
The individual variables that together make up the array are referred to as:
(a)indexed variables
(b)subscripted variables
(c)elements of the array
(d)all of the above
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
21
Declare and create an integer array that will contain the numbers 1 through 100.Use a for loop to initialize the indexed variables.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
22
Arrays are objects that are created with new just like class objects.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
23
In a vararg specification the ellipsis is not part of the Java syntax.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
24
Write a Java method that takes an integer array as a formal parameter and returns the sum of integers contained within the array.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
25
A one dimensional array is also called an array of arrays.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
26
Write a Java method as well as any facilitator methods needed to perform a sort on an array of whole numbers in descending order.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
27
You can only use array indexed variables as arguments to methods.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
28
What are three ways you can use the square brackets [ ] with an array name?
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
29
A variable of an enumerated type can have the special value null.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
30
Explain what the main methods array parameter,args,is used for.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
31
A collection class is a class whose objects store a collection of values.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
32
You may cycle through elements of a collection object using a for loop.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
33
An array of chars is the same as a String in Java.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
34
Java allows you to declare arrays with more than one index.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
35
A method can not change the values stored in the indexed variables of an array argument.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
36
How are arrays tested to see if they contain the same contents?
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
37
An array name references a memory address.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
38
Given the following character array
char[] h = {'H','E','L','L','O'};
Write a Java statement that will create a new String object from the character array.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
39
Discuss how you could represent a table of related records using a multidimensional array.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
40
Write a Java statement that declares and creates an array of Strings named Breeds.Your array should be large enough to hold the names of 100 dog breeds.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
41
Declare and create a 10 x 10 multidimensional array of doubles.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
42
Write Java statements to create a collection of integers,and to initialize each element of the collection to -1 using a for each statement.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
43
Initialize the array created in number 11 above to -1.0.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
44
What is the output of the following code?
int[] numbers = new int[10];
for(int i=0; i < numbers.length; ++i)
numbers[i] = i * 2;
for(int i=0; i < numbers.length; ++i)
System.out.print(numbers[i] + " ");
System.out.println();
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
45
What is the output of the following code?
int[] numbers = new int[10];
for(int i=0; i < numbers.length; ++i)
numbers[i] = i * 2;
for(int i=0; i < numbers.length; ++i)
System.out.print(numbers[i] / 2 + " ");
System.out.println();
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
46
Write a complete Java console application that prompts the user for a series of quiz scores.The user should type -1 to signify that the input of quiz scores is complete.Your program should then average the scores and display the result back to the user.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
47
Declare and create a multidimensional array to hold the first and last names of 10 people.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 47 flashcards in this deck.