Deck 7: Arrays
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
العب
ملء الشاشة (f)
Deck 7: Arrays
1
An array declared as an int[] can contain elements of different primitive types.
False
Explanation: An array that has been declared with a specific type may only contain elements of that type. In this case the array can only contain integers.
Explanation: An array that has been declared with a specific type may only contain elements of that type. In this case the array can only contain integers.
2
In Java, array indexes begin at 0 and end at one less than the length of the array.
True
Explanation: For an array of length n, the indexes begin at 0 and end at n - 1 in Java.
Explanation: For an array of length n, the indexes begin at 0 and end at n - 1 in Java.
3
The foreach loop can be used to process each element of an array.
True
Explanation: In Java, an array is an iterator and therefore it is possible to use the foreach loop to process individual elements.
Explanation: In Java, an array is an iterator and therefore it is possible to use the foreach loop to process individual elements.
4
Which of the statements is true about the following code snippet? int[] array = new int[25];
Array[25] = 2;
A) The integer value 2 will be assigned to the last index in the array.
B) The integer value 25 will be assigned to the second index in the array.
C) The integer value 25 will be assigned to the third value in the array.
D) This code will result in a compile-time error.
E) This code will result in a run-time error.
Array[25] = 2;
A) The integer value 2 will be assigned to the last index in the array.
B) The integer value 25 will be assigned to the second index in the array.
C) The integer value 25 will be assigned to the third value in the array.
D) This code will result in a compile-time error.
E) This code will result in a run-time error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following array declarations are invalid?
A) int[] grades = new int[5];
B) int grades[] = new int[5];
C) int[] grades = { 91, 83, 42, 100, 77 };
D) all of the above are valid
E) none of the above are valid
A) int[] grades = new int[5];
B) int grades[] = new int[5];
C) int[] grades = { 91, 83, 42, 100, 77 };
D) all of the above are valid
E) none of the above are valid
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
Every Java array is a(n) _________________, so it is possible to use a foreach loop to process each element in the array.
A) object
B) iterator
C) class
D) operator
E) none of the above
A) object
B) iterator
C) class
D) operator
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
What is the precedence of the index operator ( [ ] ) relative to other operators in Java?
A) It has the lowest precedence of all Java operators.
B) It has a higher precedence than addition, but a lower precedence than multiplication.
C) It has a higher precedence than multiplication, but a lower precedence than addition.
D) It has the highest precedence of all Java operators.
E) [ ] is not an operator.
A) It has the lowest precedence of all Java operators.
B) It has a higher precedence than addition, but a lower precedence than multiplication.
C) It has a higher precedence than multiplication, but a lower precedence than addition.
D) It has the highest precedence of all Java operators.
E) [ ] is not an operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
Suppose we have an array of String objects identified by the variable names. Which of the following for loops will not correctly process each element in the array.
A) for(int i = 0; i < names.length; i++)
B) for(String name : names)
C) for(int i = 0; i < names.length(); i++)
D) none of these will correctly process each element
E) all of these will correctly process each element
A) for(int i = 0; i < names.length; i++)
B) for(String name : names)
C) for(int i = 0; i < names.length(); i++)
D) none of these will correctly process each element
E) all of these will correctly process each element
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
In Java, array indexes always begin at ________________ .
A) -1
B) 0
C) 1
D) 2
E) you can declare an array to have any indexes you choose
A) -1
B) 0
C) 1
D) 2
E) you can declare an array to have any indexes you choose
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following statements will assign the first command-line argument sent into a Java program to a variable called argument?
A) argument = System.getFirstArgument();
B) argument = System.getArgument[1];
C) argument = System.getArgument[0];
D) argument = args[0];
E) argument = args[1];
A) argument = System.getFirstArgument();
B) argument = System.getArgument[1];
C) argument = System.getArgument[0];
D) argument = args[0];
E) argument = args[1];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following statements best describes this line of code? int[] numbers = new int[50];
A) this is the declaration and initialization of an array that holds 50 integers
B) this is a declaration and initialization of an array that holds 49 integers
C) this is a declaration and initialization of an integer array that will hold integers smaller than 50
D) this is a declaration and initialization of an integer array that will hold integers smaller than 49
E) none of the above is correct
A) this is the declaration and initialization of an array that holds 50 integers
B) this is a declaration and initialization of an array that holds 49 integers
C) this is a declaration and initialization of an integer array that will hold integers smaller than 50
D) this is a declaration and initialization of an integer array that will hold integers smaller than 49
E) none of the above is correct
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
It is possible to store 11 elements in an array that is declared in the following way.
int[] array = new int[10];
int[] array = new int[10];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following is a valid declaration for a two-dimensional array?
A) int[][] matrix;
B) int[2] matrix;
C) int[]** matrix;
D) int[] matrix;
E) none of these are correct
A) int[][] matrix;
B) int[2] matrix;
C) int[]** matrix;
D) int[] matrix;
E) none of these are correct
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
Which of the following lines of code accesses the second element of the first array in a two-dimensional array of integers, numbers, and stores the result in a variable called num?
A) num = numbers[1][2];
B) num = numbers[0][1];
C) num = numbers.getElement(1, 2);
D) num = numbers.getElement(0, 1);
E) none of the above are correct
A) num = numbers[1][2];
B) num = numbers[0][1];
C) num = numbers.getElement(1, 2);
D) num = numbers.getElement(0, 1);
E) none of the above are correct
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
What will be the output of the following code snippet? int[] array = new int[25];
System.out.println(array.length);
A) 26
B) 24
C) 25
D) This code will result in a compile time error.
E) This code will result in a run time error.
System.out.println(array.length);
A) 26
B) 24
C) 25
D) This code will result in a compile time error.
E) This code will result in a run time error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which of the following are true about two-dimensional arrays?
A) Two-dimensional integer arrays cannot be initialized via an initializer list.
B) Two-dimensional arrays can only store up to 10 elements per array (or per row).
C) Two-dimensional arrays are not accessible using for loops.
D) Two-dimensional arrays cannot hold objects.
E) None of the above are true.
A) Two-dimensional integer arrays cannot be initialized via an initializer list.
B) Two-dimensional arrays can only store up to 10 elements per array (or per row).
C) Two-dimensional arrays are not accessible using for loops.
D) Two-dimensional arrays cannot hold objects.
E) None of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
There is only one way to declare and initialized an array in Java.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
Multi-dimensional arrays that contain arrays of different lengths in any one dimension are called _________________.
A) ragged arrays
B) static arrays
C) two-dimensional arrays
D) constant arrays
E) overloaded arrays
A) ragged arrays
B) static arrays
C) two-dimensional arrays
D) constant arrays
E) overloaded arrays
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
Which of the following method declarations correctly defines a method with a variable length parameter list?
A) public int average(int[] list)
B) public int average(int ... list)
C) public int average(...)
D) public int average(int a, int b, int c, ...)
E) public int average(integers)
A) public int average(int[] list)
B) public int average(int ... list)
C) public int average(...)
D) public int average(int a, int b, int c, ...)
E) public int average(integers)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following is a true statement?
A) Arrays are passed as parameters to methods like primitive types.
B) Arrays are passed as parameters to methods like object types.
C) Arrays cannot be passed as parameters to methods.
D) All of the above are true.
E) None of the above are true.
A) Arrays are passed as parameters to methods like primitive types.
B) Arrays are passed as parameters to methods like object types.
C) Arrays cannot be passed as parameters to methods.
D) All of the above are true.
E) None of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
It is possible to send in data to a Java program via the command-line.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
Write the declaration for an array of doubles called averages that is initialized with an initializer list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
Write a method that takes in an arbitrary number of String objects, and then prints out all of them that have over 10 characters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
Write a method that accepts an array of integers and returns the smallest value in the list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
In Java it is not possible to have arrays of more than two dimensions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
Write a method that takes in at least one integer and returns the largest of all integer parameters sent in.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
Write a method called doubleSize that accepts an integer array as a parameter and returns a reference to a new integer array that is twice as long and contains all of the elements of the first array in the same positions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
Write a method called average that accepts an array of floating point numbers and returns their average.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Write a method that accepts an array of integers as a parameter and returns a reference to an array that contains the even numbers in the array original array. The returned array should have a size equal to the number of even numbers in the original array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
Write a line of code that initializes a two-dimensional array of integers using an initializer list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
Write a loop that cycles through an array of String objects called names and prints them out, one per line. Your loop should not use a foreach loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
Write the declaration for a two-dimensional array of integers that can be thought of as a table with three rows and three columns. Assign the value 3 to the cell that is in the second row and the third column.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
It is possible for a method to have a variable length parameter list, meaning that the method can take in any number of parameters of a specified data type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
An array cannot hold object types.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
Write a method that accepts an array of integers as a parameter and returns the sum of all of the integers in the array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
Write a short program that accepts an arbitrary number of command line arguments, and prints out those containing the character 'z'.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
Write a loop that cycles through an array of String objects called names and prints out the ones that start with a vowel, one per line. Your loop should use a foreach loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
Explain how arrays are passed to methods as parameters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
Write a method called containsPair that accepts an array of integers as a parameter and returns true if it contains two integers that are equal.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
If a program attempts to access an element outside of the range of the array indexes, a run-time error will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck