Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lessons
- Course Information
- Assessments
- Gradebook
- Email
- Discussion Groups
- ChatRoom
- Whiteboard
- My Folders
- Students
- Technical Support
- Announcements
- Other Courses
- Logoff
- Web 2.0 Tools
- User: Ditmar Wendt
- In Course: Adv Pl Computer Science A V9 ( 2993)
- Instructor: Lisa Lagrew Brock
- WARNING: You must not leave this exam form! If you try to click back into this exam again prior to submitting, your access to it will be denied!
- 06.05 Challenge Exam 2 (Part 1)
- Warning: There is a checkbox at the bottom of the exam form that you MUST check prior to submitting this exam. Failure to do so may cause your work to be lost.
- THIS IS A TIMED EXAM!
- Click to see time remaining
- Question 1 (Multiple Choice Worth 2 points)
- !((x > y) || (y <= 0)) is equivalent to which of the following expressions?
- I.!(x > y) || !(y <= 0)
- II.!(x > y) &&! (y <= 0)
- III. (x <= y) && (y > 0)
- I only
- II only
- III only
- I and III only
- II and III only
- Question 2 (Multiple Choice Worth 2 points)
- What does the decimal number 143 equal in the hexadecimal system?
- 8F
- C4
- 7A
- 131
- 3D
- Question 3 (Multiple Choice Worth 2 points)
- Under which of the following conditions must the boolean expression have the value
- true where n represents the length of a?
- ((i <= n) && (a[i] == 0)) || (((i >= n) && (a[i-1] == 0)))
- (i <= n) || (i >= n)
- (a[i] == 0) && (a[i-1] == 0)
- i == n
- i < n
- i > n
- Question 4 (Multiple Choice Worth 2 points)
- Assume that these String variables have been declared:
- String str1 = new String("fred");
- String str2 = new String("Fred");
- What is the value of the following expression?
- str1.equals(str2);
- true
- false
- fred
- equal
- fred.equals(Fred)
- Question 5 (Multiple Choice Worth 2 points)
- What is output by the following code fragment?
- String[ ] veggies = { "zucchini", "carrot", "spinach", "asparagus" };
- int i = 0;
- for (String item : veggies) {
- i += item.length();
- }
- System.out.println(i);
- 26
- 27
- 28
- 29
- 30
- Question 6 (Multiple Choice Worth 2 points)
- If String str1 = "Forest" and String str2 = "School", then what is the value of
- str1.compareTo(str2);?
- -1
- a value less than 0
- 0
- 1
- a value greater than 0
- Question 7 (Multiple Choice Worth 2 points)
- Suppose the following array is declared:
- int[ ] grades = {88, 92, 95, 83};
- What is the value of grades[2]?
- An ArrayIndexOutOfBoundsException occurs
- 88
- 92
- 95
- 83
- Question 8 (Multiple Choice Worth 2 points)
- What does the binary number 1001 represent in the decimal system?
- 11
- 9
- 17
- 15
- 23
- Question 9 (Multiple Choice Worth 2 points)
- The following code is designed to set index to the location of the first occurrence
- of target in the array a, and to set index to -1 if target is not found in a.
- index = 0;
- while (a[index] != target) {
- index++;
- }
- if (a[index] != target){
- index = -1;
- }
- Which of the following describes the condition under which this program segment will
- fail to perform the task described?
- Whenever target is the first element of the array
- Whenever target is the last element of the array
- Whenever target is not present in the array
- Whenever target is -1
- Whenever target = a[target]
- Question 10 (Multiple Choice Worth 2 points)
- Which of the following statements is true?
- For-each loops (or enhanced for loops) cannot be used to iterate over arrays.
- For-each loops can only be used to iterate over all array elements.
- For-each loops can be used to iterate over all array elements in reverse order.
- For loops cannot be used to iterate over all array elements in reverse order.
- For-each loops cannot be rewritten as for loops.
- Question 11 (Multiple Choice Worth 2 points)
- Suppose the following array is declared:
- int[ ] grades = {88, 92, 95, 83};
- What are the values in grades after the following code executes?
- int temp = grades[0];
- grades[0] = grades[1];
- grades[1] = temp;
- An ArrayIndexOutOfBoundsException occurs
- {92, 88, 95, 83}
- {88, 88, 95, 83}
- {92, 92, 95, 83}
- {88, 92, 95, 83}
- Question 12 (Multiple Choice Worth 2 points)
- Suppose the following array is declared:
- int[ ] grades = {88, 92, 95, 83};
- What is the value of grades[grades[0] / 22]?
- An ArrayIndexOutOfBoundsException occurs
- 4
- 88
- 92
- 95
- Question 13 (Multiple Choice Worth 2 points)
- What is printed by this code segment?
- String s = "Howdy";
- int i = s.length() - 1;
- String total = "";
- String letter;
- while (i >= 0)
- {
- letter = s.substring (i, i + 1);
- System.out.print (i + " " + letter + " ");
- total = total + letter;
- i--;
- }
- 4 H 3 o 2 w 1 d 0 y
- 0 H 1 o 2 W 3 d 4 y
- 4 y 3 d 2 w 1 o 0 H
- 0 y 1 d 2 w 3 o 4 H
- 0 1 2 3 4 H o w d y
- Question 14 (Multiple Choice Worth 2 points)
- The following code is intended to calculate the sum of the first five positive even
- integers.
- int sum = 2, k;
- for(k = 4; k <= 12; k += 2)
- {
- sum += k;
- }
- What is wrong with this code segment?
- The segment calculates the sum of the first four positive even integers.
- The segment calculates the sum of the first six positive even integers.
- The segment calculates the sum of the first seven positive even integers.
- The variable sum is incorrectly initialized. The segment would work correctly if sum
- was initialized to 0.
- The segment works as intended.
- Question 15 (Multiple Choice Worth 2 points)
- Assume that a is an array of two or more integers, and that b and c are integers.
- What is the result of the following code?
- c = 0;
- b = 1;
- if (a.length > 0) {
- c = a[0];
- }
- while (b < a.length){
- if (a[b] < c) {
- c = a[b];
- }
- b++;
- }
- b contains the highest value in the array
- b contains the lowest value in the array
- c contains the highest value in the array
- c contains the lowest value in the array
- An endless loop occurs
- Question 16 (Multiple Choice Worth 2 points)
- Given the following code:
- if (n == 2)
- {
- k -= 2;
- }
- else if (n == 3)
- {
- k -= 3;
- }
- can be rewritten as:
- if (< condition >) {
- < assignment statement >;
- }
- Assume that evaluating < condition > does not change the values stored in n and k. Which
- of the following could be used as < assignment statement >?
- k -= n;
- k -= 1;
- k -= 2;
- k += n;
- k = n – k;
- Question 17 (Multiple Choice Worth 2 points)
- Consider the following code segment:
- int i;
- for (i = 0; i <= 10; i++) {
- if ((i % 3) == 1) {
- System.out.print(i + " ");
- }
- }
- What is printed as a result of executing this code segment?
- 1 2 3 4 5 6 7 8 9 10
- 1 3 5 7 9
- 1 3 7 9
- 1 4 7
- 1 4 7 10
- Question 18 (Multiple Choice Worth 2 points)
- Suppose the following array is declared:
- int[ ] grades = {88, 92, 95, 83};
- and the following integer is declared:
- int index = 1 + 6 % 3;
- What is the value of grades[index]?
- An ArrayIndexOutOfBoundsException occurs
- 88
- 92
- 95
- 83
- Question 19 (Multiple Choice Worth 2 points)
- Given the following code:
- int i = 100;
- int j = 10;
- while (i > 0)
- {
- i = i / j;
- j = 1 + j % 5;
- }
- What is the value of i after this code executes?
- 0
- 1
- 2
- 5
- 10
- Question 20 (Multiple Choice Worth 2 points)
- Consider the following code, What are the values in array after the following code executes?
- int[ ] array = new int[3];
- int index = 1;
- array[index] = index - 1;
- index++;
- array[index] = array[index - 1] - 1;
- array[index - 2] = index % 3;
- {0, 0, 0}
- {0, 0, 2}
- {2, 0, 0}
- {2, 0, -1}
- {3, 0, 2}
- Question 21 (Multiple Choice Worth 2 points)
- If a, b, and c are boolean variables such that a is true, b is false, and c is true,
- which of these expressions:
- I.!((a || b) && c)
- II.!a && (b && c)
- III.!a && (b || c)
- evaluates to false?
- I only
- II only
- III only
- II and III only
- I, II, and III
- Question 22 (Multiple Choice Worth 2 points)
- What is output by the following program?
- int i = 6;
- while (i >= 2) {
- System.out.print (i + " ");
- if ((i % 2) == 0) {
- i = i / 2;
- } else {
- i = i + 1;
- }
- }
- 6 7 4 2
- 6 3 4 2
- 6 2 4 1
- 6 5 4 3 2
- 6 3 5 2
- Question 23 (Multiple Choice Worth 2 points)
- Consider the following two code segments. In both, assume that n is an integer
- variable that has been declared and initialized.
- Segment 1
- int prod = 1;
- int i;
- for (i = 2; i <= n; i++) {
- prod *= i;
- }
- System.out.println(prod);
- Segment 2
- int prod = 1;
- int i = 2;
- while (i <= n) {
- prod = prod * i;
- i++;
- }
- System.out.println(prod);
- For which integer values of n do these code segments print the same result?
- Only n > 1
- Only n < 1
- Only n == 1
- Only n >= 1
- Any integer n produces the same result
- Question 24 (Multiple Choice Worth 2 points)
- In the following algorithm, which constant should be assigned to maximum to ensure that the algorithm finds the largest integer?
- maximum = <<constant>>;for(int current = 0; current < numbers.length; current ++){if (maximum < numbers[current])maximum = numbers[current];}
- Int.MIN_VALUE
- Int.MAX_VALUE
- Integer.MAX_VALUE
- Integer.MIN_VALUE
- Question 25 (Multiple Choice Worth 2 points)
- Assume that age has been declared as an int variable. Which expression is true
- whenever age indicates that the person is a teenager?
- ((age < 20) && (age >= 13))
- ((age < 20) || (age >= 13))
- ((age <= 19) && (age < 13))
- ((age <= 19) || (age >= 13))
- ((age <= 19) && (age >= 12))
- Question 26 (Multiple Choice Worth 2 points)
- The Integer.MIN_VALUE constant has the value of ____.
- -231
- -231 - 1
- -231 - 1
- -231 + 1
- YOU MUST CHECK THE BOX BELOW PRIOR TO SUBMITTING YOUR EXAM!
- Check this box to indicate you are ready to submit your exam
- Tutorial Explorer Compass Toolbox Calendar Notification Feature Security Workload Usage Users Group
- You have 2 Unread E-Mail Messages
- Current course:
- Related Help Center Topics
- Taking Exams
- Proctored Exams
- Question Types
Advertisement
Add Comment
Please, Sign In to add comment