Deck 6: Arrays

Full screen (f)
exit full mode
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
Use Space or
up arrow
down arrow
to flip the card.
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 arrays length instance variables value can be changed by a program.
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 double0.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
An ArrayIndexOutOfBounds error is a:

A)compiler error
B)syntax error
C)logic error
D)all of the above
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
This type of loop provides a convenient mechanism to iterate through every element of an array.

A)for each
B)for
C)do while
D)while
Question
What is the correct expression for accessing the 5< sup >th< /sup > element in an array named colors?

A)colors[3]
B)colors[4]
C)colors[5]
D)colors[6]
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
Consider the following array: <strong>Consider the following array:   What is the value of myArray[myArray[1] - myArray[0]]</strong> A)7 B)9 C)-3 D)6 <div style=padding-top: 35px> What is the value of myArray[myArray[1] - myArray[0]]

A)7
B)9
C)-3
D)6
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
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
An array is a collection of variables all of the same type.
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
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
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
The subscript of the first indexed variable in an array is:

A)0
B)1
C)2
D)3
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
An array has only one public instance variable,which is named length.
Question
A method can not change the values stored in the indexed variables of an array argument.
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
You may cycle through elements of a collection object using a for loop.
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 variable of an enumerated type can have the special value null.
Question
Arrays are objects that are created with new just like class objects.
Question
What are three ways you can use the square brackets [ ] with an array name?
Question
Java allows you to declare arrays with more than one index.
Question
An array of chars is the same as a String in Java.
Question
How are arrays tested to see if they contain the same contents?
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
Explain what the main methods array parameter,args,is used for.
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
You can only use array indexed variables as arguments to methods.
Question
A collection class is a class whose objects store a collection of values.
Question
A one dimensional array is also called an array of arrays.
Question
An array name references a memory address.
Question
In a vararg specification the ellipsis is not part of the Java syntax.
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
Discuss how you could represent a table of related records using a multidimensional array.
Question
What is the output of the following code?
int[] numbers = new int[10];
forint i=0;i < numbers.length;++i)
numbers[i] = i * 2;
forint i=0;i < numbers.length;++i)
System.out.printnumbers[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
Initialize the array created in number 11 above to -1.0.
Question
Declare and create a 10 x 10 multidimensional array of doubles.
Question
Declare and create a multidimensional array to hold the first and last names of 10 people.
Question
What is the output of the following code?
int[] numbers = new int[10];
forint i=0;i < numbers.length;++i)
numbers[i] = i * 2;
forint i=0;i < numbers.length;++i)
System.out.printnumbers[i] + " ");
System.out.println);
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Arrays
1
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
2
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
B
3
An arrays length instance variables value can be changed by a program.
False
4
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 double0.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 46 flashcards in this deck.
Unlock Deck
k this deck
5
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 46 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 46 flashcards in this deck.
Unlock Deck
k this deck
7
This type of loop provides a convenient mechanism to iterate through every element of an array.

A)for each
B)for
C)do while
D)while
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
What is the correct expression for accessing the 5< sup >th< /sup > 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 46 flashcards in this deck.
Unlock Deck
k this deck
9
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 46 flashcards in this deck.
Unlock Deck
k this deck
10
Consider the following array: <strong>Consider the following array:   What is the value of myArray[myArray[1] - myArray[0]]</strong> A)7 B)9 C)-3 D)6 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 46 flashcards in this deck.
Unlock Deck
k this deck
11
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 46 flashcards in this deck.
Unlock Deck
k this deck
12
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 46 flashcards in this deck.
Unlock Deck
k this deck
13
An array is a collection of variables all of the same type.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
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 46 flashcards in this deck.
Unlock Deck
k this deck
15
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 46 flashcards in this deck.
Unlock Deck
k this deck
16
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 46 flashcards in this deck.
Unlock Deck
k this deck
17
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 46 flashcards in this deck.
Unlock Deck
k this deck
18
The subscript of the first indexed variable in an array is:

A)0
B)1
C)2
D)3
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
19
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 46 flashcards in this deck.
Unlock Deck
k this deck
20
An array has only one public instance variable,which is named length.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
21
A method can not change the values stored in the indexed variables of an array argument.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
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 46 flashcards in this deck.
Unlock Deck
k this deck
23
You may cycle through elements of a collection object using a for loop.
Unlock Deck
Unlock for access to all 46 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 46 flashcards in this deck.
Unlock Deck
k this deck
25
A variable of an enumerated type can have the special value null.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
Arrays are objects that are created with new just like class objects.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
What are three ways you can use the square brackets [ ] with an array name?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
Java allows you to declare arrays with more than one index.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
An array of chars is the same as a String in Java.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
How are arrays tested to see if they contain the same contents?
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
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 46 flashcards in this deck.
Unlock Deck
k this deck
32
Explain what the main methods array parameter,args,is used for.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
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 46 flashcards in this deck.
Unlock Deck
k this deck
34
You can only use array indexed variables as arguments to methods.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
35
A collection class is a class whose objects store a collection of values.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
36
A one dimensional array is also called an array of arrays.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
An array name references a memory address.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
38
In a vararg specification the ellipsis is not part of the Java syntax.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
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 46 flashcards in this deck.
Unlock Deck
k this deck
40
Discuss how you could represent a table of related records using a multidimensional array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
What is the output of the following code?
int[] numbers = new int[10];
forint i=0;i < numbers.length;++i)
numbers[i] = i * 2;
forint i=0;i < numbers.length;++i)
System.out.printnumbers[i] / 2 + " ");
System.out.println);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
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 46 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 46 flashcards in this deck.
Unlock Deck
k this deck
44
Declare and create a 10 x 10 multidimensional array of doubles.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
Declare and create a multidimensional array to hold the first and last names of 10 people.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
46
What is the output of the following code?
int[] numbers = new int[10];
forint i=0;i < numbers.length;++i)
numbers[i] = i * 2;
forint i=0;i < numbers.length;++i)
System.out.printnumbers[i] + " ");
System.out.println);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 46 flashcards in this deck.