Deck 8: Single-Dimensional Arrays

ملء الشاشة (f)
exit full mode
سؤال
We use the new keyword to instantiate an array using an initialization list.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Before we can instantiate objects inside an array, we must first instantiate the array.
سؤال
In order to find the maximum value of an element in an array, we must use the maxVal variable.
سؤال
To avoid encapsulation problems resulting from shared array references, it may be necessary to copy the elements of the array into a new or temporary array.
سؤال
An Insertion Sort works by implementing a triple loop.
سؤال
During an Insertion Sort, the value of the element that we are currently inserting (at index i) is stored in some temporary variable.
سؤال
An Insertion Sort runs much more efficiently than a Binary Search.
سؤال
During a Selection Sort, a portion of an array is known as a(n) __________.
سؤال
We want to store the number of referrals to our website from the top four search engines (Google, Yahoo, Bing, and Ask). Which of the following array declarations would you use?

A) int [] searchEngineReferrals;
B) int [4] google, yahoo, bing, ask;
C) int [ ] google, [ ] yahoo, [ ] bing, [ ] ask;
D) None of these is correct.
سؤال
When we declare an array, we also allocate memory for the array at the same time.
سؤال
Considering the functionality of length in an array, which of the following statements is true?

A) length functions as an instance variable.
B) length functions as a method.
C) length is always a double.
D) size and length can be used interchangeably.
سؤال
The last element in an array always has an index of 1 less than the number of elements.
سؤال
What kind of loop is generally employed to print every element of an array, in order?

A) for loop
B) while loop
C) infinite loop
D) zero loop
سؤال
The statement for ( int i = 0; i <= arrayName.length; i++ ) has generated a runtime exception. What would the corrected syntax look like?

A) for ( int i = 0; i <= arrayName.length; ++i )
B) for ( int i = 1; i < arrayName.length; i++ )
C) for ( int i = 0; i < arrayName.length( ); i++ )
D) for ( int i = 0; i < arrayName.length; i++ )
سؤال
Which of the following is not an attribute of arrays when used in user-defined classes?

A) They are an instance variable.
B) They are a parameter to a method.
C) They share references with the client.
D) They are a method.
E) They are a local variable inside a method.
سؤال
When defining a method that takes an array as a parameter, we use the following syntax:
accessModifier returnType methodName( arrayName )
سؤال
Which of the following statements is not true of a Selection Sort algorithm?

A) It loops through the elements of an array multiple times.
B) It re-orders the elements of an array in ascending or descending order.
C) It stops looping when the subarray has only one element left.
D) It indicates when it is finished by returning -1.
سؤال
Parallel arrays are best used when we have lists of items of the same length with different data types.
سؤال
Suppose we want to track the winning lottery numbers (ranging from 1 to 72) and count the number of times each number comes up over the course of a month. In this scenario, we would be wise to:

A) set up an array of counters with 72 elements.
B) set up 72 counters with if/else statements.
C) set up an array of counters with 72 elements and set up 72 counters with if/else statements.
D) None of these is correct.
سؤال
In a lottery number tracking scenario, in which the number 0 is not a possible winning number and thus would never be counted, it would be wise to create an array with one additional element and ignore element 0 altogether.
سؤال
Assume we have a situation where the number of inputs cannot possibly be determined until run time. The Java feature that we would use to specify that the method accept a variable number of arguments is called:

A) varparam.
B) varargs.
C) varinput.
D) varoutput.
سؤال
When we have a parameter specified by a method using the varargs syntax, that parameter must be listed as the first one in the method header.
سؤال
When we instantiate an array:

A) we allocate memory for the array.
B) the elements are given initial values.
C) we use the keyword new.
D) All of these are correct.
سؤال
To compare the elements of an array for equality, which of the following actions must we take first?

A) First, make a backup copy of the two arrays.
B) First, make sure the two arrays are the same length.
C) First, run a for loop to compare each array, element to element.
D) None of these is correct.
سؤال
Which of the following is not a method used to display array data as a bar chart?

A) setFill method
B) fillRect method
C) barStart method
D) fillText method
سؤال
At the beginning of a Selection Sort, the entire unsorted array is considered to be a subarray.
سؤال
In the header public static void main( String [ ] args ), the main method receives a String ____________ as a parameter.
سؤال
The position of an element within an array is known as its __________.
سؤال
The compareTo method of the String class compares the values of two ____________.
سؤال
The sorting algorithm that mirrors inserting cards one at a time into a hand is called __________.
سؤال
Suppose you are looking for the name of your friend, Mike Jones, in the telephone directory. You open the book in the middle and look at the name at the top of the left page; it starts with an L. You mark that page and look halfway between the first page and that page. As you continue to apply this strategy, you are using the _____________ algorithm.
سؤال
Where is the error in the array declaration int [5] numbers;?

A) There is no error.
B) The square brackets should be empty.
C) There should be no space between int and [.
D) It should be int numbers[5];.
سؤال
To access the element at index i of an array named grades, we use:

A) grades.
B) grades[ i ].
C) grades( i ).
D) grades{ i }.
سؤال
If an array has n elements, then the last index is:

A) n.
B) n + 1.
C) n − 1.
سؤال
Which of the following would we use to access the number of elements in an array named grades?

A) grades
B) grades.size( )
C) grades.size
D) grades.length( )
E) grades.length
سؤال
When processing all the elements of an array named grades using a for loop, what is the for loop header?

A) for( int i = 1; i <= grades.length; i++ )
B) for( int i = 1; i < grades.length; i++ )
C) for( int i = 0; i <= grades.length; i++ )
D) for( int i = 0; i < grades.length; i++ )
سؤال
When computing the maximum value in an array of integers, you should initialize the maximum value to:

A) 0.
B) 1.
C) the first element in the array.
D) 100.
سؤال
Which of the following is correct regarding the method header public static void main( String [ ] args )?

A) args is an array of Strings
B) args is a String
C) args is a void array
D) main is an array
سؤال
Insertion Sort uses a:

A) single loop.
B) double loop.
C) triple loop.
سؤال
In an array, we can have a mix of integers and Strings.
سؤال
When declaring an array, we use a set of square brackets.
سؤال
We can instantiate an array by assigning values when the array is declared.
سؤال
We cannot combine the declaration and instantiation of an array into one statement.
سؤال
It is possible to have an array of objects.
سؤال
To process all the elements of an array, we use a loop.
سؤال
To compare two arrays for equality, you call the equals method with the first array and pass the second array as the argument.
سؤال
An array can be an instance variable of a class.
سؤال
A method cannot return an array.
سؤال
We can pass an array parameter to a method.
سؤال
When we instantiate an array, we use the keyword __________.
سؤال
Looking for a value in an array by looping through all the elements of an array in order is called a(n) __________.
سؤال
What happens if you try to access an array element using a negative index or an index greater than or equal to the number of elements in the array?
سؤال
Why is a NullPointerException generated after the following statements are executed?
String [] words = new String[10];
System.out.println( words[0].length( ) );
سؤال
How do you copy an array into another array?
سؤال
How do you compare two arrays for equality?
سؤال
Name two algorithms for sorting arrays.
سؤال
We have made an array declaration of double dailyWindSpeeds [ ]; What is another valid way of writing this same declaration with an alternative syntax?
سؤال
When an array is created with the new operator, the elements of the array are automatically assigned default values. Can you identify those values for numeric elements, boolean elements, char elements, and object references?
سؤال
What is the primary difference in functionality between .length used in an array and length ( ) used in Strings?
سؤال
Under what conditions are ArrayIndexOutOfBounds exceptions generated?
سؤال
If we use the following code to make a separate copy of the array called testScores, will it work? Why or why not?
int [ ] testScores = {95, 100, 89, 92, 25};
int [ ] copyOfTestScores = testScores;
سؤال
Assume that we have an array called propertyTaxes whose elements are objects. Using a for loop, we make a copy of that array called propertyTaxesCopy. When an object in propertyTaxes changes, does it have any effect on the object in propertyTaxesCopy? Why or why not?
سؤال
Explain how the Sequential Search algorithm works within unsorted arrays.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/63
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 8: Single-Dimensional Arrays
1
We use the new keyword to instantiate an array using an initialization list.
False
2
Before we can instantiate objects inside an array, we must first instantiate the array.
True
3
In order to find the maximum value of an element in an array, we must use the maxVal variable.
False
4
To avoid encapsulation problems resulting from shared array references, it may be necessary to copy the elements of the array into a new or temporary array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
5
An Insertion Sort works by implementing a triple loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
6
During an Insertion Sort, the value of the element that we are currently inserting (at index i) is stored in some temporary variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
7
An Insertion Sort runs much more efficiently than a Binary Search.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
8
During a Selection Sort, a portion of an array is known as a(n) __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
9
We want to store the number of referrals to our website from the top four search engines (Google, Yahoo, Bing, and Ask). Which of the following array declarations would you use?

A) int [] searchEngineReferrals;
B) int [4] google, yahoo, bing, ask;
C) int [ ] google, [ ] yahoo, [ ] bing, [ ] ask;
D) None of these is correct.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
10
When we declare an array, we also allocate memory for the array at the same time.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
11
Considering the functionality of length in an array, which of the following statements is true?

A) length functions as an instance variable.
B) length functions as a method.
C) length is always a double.
D) size and length can be used interchangeably.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
12
The last element in an array always has an index of 1 less than the number of elements.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
13
What kind of loop is generally employed to print every element of an array, in order?

A) for loop
B) while loop
C) infinite loop
D) zero loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
14
The statement for ( int i = 0; i <= arrayName.length; i++ ) has generated a runtime exception. What would the corrected syntax look like?

A) for ( int i = 0; i <= arrayName.length; ++i )
B) for ( int i = 1; i < arrayName.length; i++ )
C) for ( int i = 0; i < arrayName.length( ); i++ )
D) for ( int i = 0; i < arrayName.length; i++ )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which of the following is not an attribute of arrays when used in user-defined classes?

A) They are an instance variable.
B) They are a parameter to a method.
C) They share references with the client.
D) They are a method.
E) They are a local variable inside a method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
16
When defining a method that takes an array as a parameter, we use the following syntax:
accessModifier returnType methodName( arrayName )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the following statements is not true of a Selection Sort algorithm?

A) It loops through the elements of an array multiple times.
B) It re-orders the elements of an array in ascending or descending order.
C) It stops looping when the subarray has only one element left.
D) It indicates when it is finished by returning -1.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
18
Parallel arrays are best used when we have lists of items of the same length with different data types.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
19
Suppose we want to track the winning lottery numbers (ranging from 1 to 72) and count the number of times each number comes up over the course of a month. In this scenario, we would be wise to:

A) set up an array of counters with 72 elements.
B) set up 72 counters with if/else statements.
C) set up an array of counters with 72 elements and set up 72 counters with if/else statements.
D) None of these is correct.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
20
In a lottery number tracking scenario, in which the number 0 is not a possible winning number and thus would never be counted, it would be wise to create an array with one additional element and ignore element 0 altogether.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
21
Assume we have a situation where the number of inputs cannot possibly be determined until run time. The Java feature that we would use to specify that the method accept a variable number of arguments is called:

A) varparam.
B) varargs.
C) varinput.
D) varoutput.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
22
When we have a parameter specified by a method using the varargs syntax, that parameter must be listed as the first one in the method header.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
23
When we instantiate an array:

A) we allocate memory for the array.
B) the elements are given initial values.
C) we use the keyword new.
D) All of these are correct.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
24
To compare the elements of an array for equality, which of the following actions must we take first?

A) First, make a backup copy of the two arrays.
B) First, make sure the two arrays are the same length.
C) First, run a for loop to compare each array, element to element.
D) None of these is correct.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which of the following is not a method used to display array data as a bar chart?

A) setFill method
B) fillRect method
C) barStart method
D) fillText method
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
26
At the beginning of a Selection Sort, the entire unsorted array is considered to be a subarray.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
27
In the header public static void main( String [ ] args ), the main method receives a String ____________ as a parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
28
The position of an element within an array is known as its __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
29
The compareTo method of the String class compares the values of two ____________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
30
The sorting algorithm that mirrors inserting cards one at a time into a hand is called __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
31
Suppose you are looking for the name of your friend, Mike Jones, in the telephone directory. You open the book in the middle and look at the name at the top of the left page; it starts with an L. You mark that page and look halfway between the first page and that page. As you continue to apply this strategy, you are using the _____________ algorithm.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
32
Where is the error in the array declaration int [5] numbers;?

A) There is no error.
B) The square brackets should be empty.
C) There should be no space between int and [.
D) It should be int numbers[5];.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
33
To access the element at index i of an array named grades, we use:

A) grades.
B) grades[ i ].
C) grades( i ).
D) grades{ i }.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
34
If an array has n elements, then the last index is:

A) n.
B) n + 1.
C) n − 1.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which of the following would we use to access the number of elements in an array named grades?

A) grades
B) grades.size( )
C) grades.size
D) grades.length( )
E) grades.length
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
36
When processing all the elements of an array named grades using a for loop, what is the for loop header?

A) for( int i = 1; i <= grades.length; i++ )
B) for( int i = 1; i < grades.length; i++ )
C) for( int i = 0; i <= grades.length; i++ )
D) for( int i = 0; i < grades.length; i++ )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
37
When computing the maximum value in an array of integers, you should initialize the maximum value to:

A) 0.
B) 1.
C) the first element in the array.
D) 100.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
38
Which of the following is correct regarding the method header public static void main( String [ ] args )?

A) args is an array of Strings
B) args is a String
C) args is a void array
D) main is an array
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
39
Insertion Sort uses a:

A) single loop.
B) double loop.
C) triple loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
40
In an array, we can have a mix of integers and Strings.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
41
When declaring an array, we use a set of square brackets.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
42
We can instantiate an array by assigning values when the array is declared.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
43
We cannot combine the declaration and instantiation of an array into one statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
44
It is possible to have an array of objects.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
45
To process all the elements of an array, we use a loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
46
To compare two arrays for equality, you call the equals method with the first array and pass the second array as the argument.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
47
An array can be an instance variable of a class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
48
A method cannot return an array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
49
We can pass an array parameter to a method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
50
When we instantiate an array, we use the keyword __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
51
Looking for a value in an array by looping through all the elements of an array in order is called a(n) __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
52
What happens if you try to access an array element using a negative index or an index greater than or equal to the number of elements in the array?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
53
Why is a NullPointerException generated after the following statements are executed?
String [] words = new String[10];
System.out.println( words[0].length( ) );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
54
How do you copy an array into another array?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
55
How do you compare two arrays for equality?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
56
Name two algorithms for sorting arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
57
We have made an array declaration of double dailyWindSpeeds [ ]; What is another valid way of writing this same declaration with an alternative syntax?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
58
When an array is created with the new operator, the elements of the array are automatically assigned default values. Can you identify those values for numeric elements, boolean elements, char elements, and object references?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
59
What is the primary difference in functionality between .length used in an array and length ( ) used in Strings?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
60
Under what conditions are ArrayIndexOutOfBounds exceptions generated?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
61
If we use the following code to make a separate copy of the array called testScores, will it work? Why or why not?
int [ ] testScores = {95, 100, 89, 92, 25};
int [ ] copyOfTestScores = testScores;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
62
Assume that we have an array called propertyTaxes whose elements are objects. Using a for loop, we make a copy of that array called propertyTaxesCopy. When an object in propertyTaxes changes, does it have any effect on the object in propertyTaxesCopy? Why or why not?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
63
Explain how the Sequential Search algorithm works within unsorted arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 63 في هذه المجموعة.