Deck 3: Selections
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/21
العب
ملء الشاشة (f)
Deck 3: Selections
1
To create a set that consists of string elements "red", "green", and "blue", use A. new HashSet(new String[]{"red", "green", "blue"})
B) new Set(Arrays.asList(new String[]{"red", "green", "blue"}))
"}))
D) new HashSet({"red", "green", "blue"})
B) new Set(Arrays.asList(new String[]{"red", "green", "blue"}))
"}))
D) new HashSet({"red", "green", "blue"})
C
2
Suppose List list = new ArrayList(). Which of the following operations are correct? A. list.add(new Integer(100));
B) list.add(new ArrayList());
C) list.add("Red");
D) list.add(new java.util.Date());
B) list.add(new ArrayList());
C) list.add("Red");
D) list.add(new java.util.Date());
C
3
To create a list to store integers, use B. ArrayList list = new ArrayList();
C) ArrayList
C) ArrayList
A
4
Show the time complexity of the following program:
for (int k = 0; k < 10; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print('*');
}
}
}
for (int k = 0; k < 10; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print('*');
}
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
5
Write a recursive mathematical definition for computing
for a positive integer.
for a positive integer. فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
6
(Displaying words) Write a program that reads words separated by spaces from a text file and displays words in ascending order. (If two words are the same, display only one). Pass the text filename from the command line.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
7
Suppose your program frequently tests whether a student is in a soccer team, what is the best data structure to store the students in a soccer team? A. ArrayList
C) TreeSet
D) LinkedList
E) Vector
C) TreeSet
D) LinkedList
E) Vector
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
8
Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants? B. Array List
C) Queue
D) Linked List
C) Queue
D) Linked List
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
9
Are there any compile errors in (a) and (b)? 

فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which method do you use to remove an element from a set or list named x? B. x.removes(element)
C) x.delete(element)
D) None of the above
E) x.deletes(element)
C) x.delete(element)
D) None of the above
E) x.deletes(element)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following is correct to sort the elements in a list lst? A. new LinkedList(new String[]{"red", "green", "blue"})
B) lst.sort()
C) Arrays.sort(lst)
B) lst.sort()
C) Arrays.sort(lst)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
12
Fill in the code in Comparable______ c = new Date(); A.
B)
C)
B)
C)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
13
Design an efficient O(logn) time algorithm for computing
. (Describe it using a pseudo code)
. (Describe it using a pseudo code) فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
14
Suppose that set1 (Set) is a set that contains the strings "red", "yellow", "green", and that set2 (Set) is another set that contains the strings "red", "yellow", "blue". Answer the following questions: (All the questions are independent)
What are set1 and set2 after executing set1.addAll(set2)?
What are set1 and set2 after executing set1.add(set2)?
What are set1 and set2 after executing set1.removeAll(set2)?
What are set1 and set2 after executing set1.remove(set2)?
What are set1 and set2 after executing set1.retainAll(set2)?
What is set1 after executing set1.clear()?
What are set1 and set2 after executing set1.addAll(set2)?
What are set1 and set2 after executing set1.add(set2)?
What are set1 and set2 after executing set1.removeAll(set2)?
What are set1 and set2 after executing set1.remove(set2)?
What are set1 and set2 after executing set1.retainAll(set2)?
What is set1 after executing set1.clear()?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
15
Show the output of the following program: 

فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
16
To find a maximum object in an array of strings (e.g., String[] names = {"red", "green", "blue"}), use A. Arrays.max(names)
B) Collections.max(Arrays.asList(names))
C) Arrays.sort(names)
D) Collections.max(names)
E) None of the above
B) Collections.max(Arrays.asList(names))
C) Arrays.sort(names)
D) Collections.max(names)
E) None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the data types below could be used to store elements in their natural order based on the compareTo method. A. TreeSet
B) Collection
C) HashSet
D) LinkedHashSet
E) Set
B) Collection
C) HashSet
D) LinkedHashSet
E) Set
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
18
How many times is the factorial method in Listing 20.1 invoked for factorial(5)? B. 3
C) 5
D) 4
C) 5
D) 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
19
Show the printout of the following code:
Test {
main(String[] args) {
Map map = LinkedHashMap();
map.put("123", "John Smith");
map.put("111", "George Smith");
map.put("123", "Steve Yao");
map.put("222", "Steve Yao");
System.out.println("(1) " + map);
System.out.println("(2) " + new TreeMap(map));
}
}
Test {
main(String[] args) {
Map
map.put("123", "John Smith");
map.put("111", "George Smith");
map.put("123", "Steve Yao");
map.put("222", "Steve Yao");
System.out.println("(1) " + map);
System.out.println("(2) " + new TreeMap(map));
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
20
To declare an interface named A with two generic types, use A. public interface A(E, F) { ... }
B) public interface A { ... }
D) public interface A(E) { ... }
B) public interface A
D) public interface A(E) { ... }
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck
21
Suppose your program frequently tests whether a student is in a soccer team and also need to know the student's information such as phone number, address, and age, what is the best data structure to store the students in a soccer team? A. ArrayList
C) TreeMap
D) LinkedList
E) HashSet
C) TreeMap
D) LinkedList
E) HashSet
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 21 في هذه المجموعة.
فتح الحزمة
k this deck

