Guest User

Untitled

a guest
Mar 14th, 2010
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.84 KB | None | 0 0
  1. Lessons
  2. Course Information
  3. Assessments
  4. Gradebook
  5. Email
  6. Discussion Groups
  7. ChatRoom
  8. Whiteboard
  9. My Folders
  10. Students
  11. Technical Support
  12. Announcements
  13. Other Courses
  14. Logoff
  15. Web 2.0 Tools
  16.        
  17. User: Ditmar Wendt
  18. In Course: Adv Pl Computer Science A V9 ( 2993)
  19. Instructor: Lisa Lagrew Brock
  20.  
  21. 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!
  22.  
  23. 06.05 Challenge Exam 2 (Part 1)
  24.  
  25. 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.
  26.  
  27. THIS IS A TIMED EXAM!
  28.  
  29. Click to see time remaining
  30.  
  31. Question 1 (Multiple Choice Worth 2 points)
  32.  
  33. !((x > y) || (y <= 0)) is equivalent to which of the following expressions?
  34.  
  35. I.!(x > y) || !(y <= 0)
  36. II.!(x > y) &&! (y <= 0)
  37. III. (x <= y) && (y > 0)
  38.  
  39. I only
  40.  
  41. II only
  42.  
  43. III only
  44.  
  45. I and III only
  46.  
  47. II and III only
  48.  
  49. Question 2 (Multiple Choice Worth 2 points)
  50.  
  51. What does the decimal number 143 equal in the hexadecimal system?
  52.  
  53. 8F
  54.  
  55. C4
  56.  
  57. 7A
  58.  
  59. 131
  60.  
  61. 3D
  62.  
  63. Question 3 (Multiple Choice Worth 2 points)
  64.  
  65. Under which of the following conditions must the boolean expression have the value
  66. true where n represents the length of a?
  67.  
  68. ((i <= n) && (a[i] == 0)) || (((i >= n) && (a[i-1] == 0)))
  69.  
  70. (i <= n) || (i >= n)
  71.  
  72. (a[i] == 0) && (a[i-1] == 0)
  73.  
  74. i == n
  75.  
  76. i < n
  77.  
  78. i > n
  79.  
  80. Question 4 (Multiple Choice Worth 2 points)
  81.  
  82. Assume that these String variables have been declared:
  83.  
  84. String str1 = new String("fred");
  85. String str2 = new String("Fred");
  86. What is the value of the following expression?
  87. str1.equals(str2);
  88.  
  89. true
  90.  
  91. false
  92.  
  93. fred
  94.  
  95. equal
  96.  
  97. fred.equals(Fred)
  98.  
  99. Question 5 (Multiple Choice Worth 2 points)
  100.  
  101. What is output by the following code fragment?
  102.  
  103. String[ ] veggies = { "zucchini", "carrot", "spinach", "asparagus" };
  104.  
  105. int i = 0;
  106.  
  107. for (String item : veggies) {
  108.  
  109. i += item.length();
  110.  
  111. }
  112.  
  113. System.out.println(i);
  114.  
  115. 26
  116.  
  117. 27
  118.  
  119. 28
  120.  
  121. 29
  122.  
  123. 30
  124.  
  125. Question 6 (Multiple Choice Worth 2 points)
  126.  
  127. If String str1 = "Forest" and String str2 = "School", then what is the value of
  128. str1.compareTo(str2);?
  129.  
  130. -1
  131.  
  132. a value less than 0
  133.  
  134. 0
  135.  
  136. 1
  137.  
  138. a value greater than 0
  139.  
  140. Question 7 (Multiple Choice Worth 2 points)
  141.  
  142. Suppose the following array is declared:
  143.  
  144. int[ ] grades = {88, 92, 95, 83};
  145. What is the value of grades[2]?
  146.  
  147. An ArrayIndexOutOfBoundsException occurs
  148.  
  149. 88
  150.  
  151. 92
  152.  
  153. 95
  154.  
  155. 83
  156.  
  157. Question 8 (Multiple Choice Worth 2 points)
  158.  
  159. What does the binary number 1001 represent in the decimal system?
  160.  
  161. 11
  162.  
  163. 9
  164.  
  165. 17
  166.  
  167. 15
  168.  
  169. 23
  170.  
  171. Question 9 (Multiple Choice Worth 2 points)
  172.  
  173. The following code is designed to set index to the location of the first occurrence
  174. of target in the array a, and to set index to -1 if target is not found in a.
  175.  
  176. index = 0;
  177. while (a[index] != target) {
  178. index++;
  179. }
  180. if (a[index] != target){
  181. index = -1;
  182. }
  183. Which of the following describes the condition under which this program segment will
  184. fail to perform the task described?
  185.  
  186. Whenever target is the first element of the array
  187.  
  188. Whenever target is the last element of the array
  189.  
  190. Whenever target is not present in the array
  191.  
  192. Whenever target is -1
  193.  
  194. Whenever target = a[target]
  195.  
  196. Question 10 (Multiple Choice Worth 2 points)
  197.  
  198. Which of the following statements is true?
  199.  
  200. For-each loops (or enhanced for loops) cannot be used to iterate over arrays.
  201.  
  202. For-each loops can only be used to iterate over all array elements.
  203.  
  204. For-each loops can be used to iterate over all array elements in reverse order.
  205.  
  206. For loops cannot be used to iterate over all array elements in reverse order.
  207.  
  208. For-each loops cannot be rewritten as for loops.
  209.  
  210. Question 11 (Multiple Choice Worth 2 points)
  211.  
  212. Suppose the following array is declared:
  213.  
  214. int[ ] grades = {88, 92, 95, 83};
  215.  
  216. What are the values in grades after the following code executes?
  217.  
  218. int temp = grades[0];
  219.  
  220. grades[0] = grades[1];
  221.  
  222. grades[1] = temp;
  223.  
  224. An ArrayIndexOutOfBoundsException occurs
  225.  
  226. {92, 88, 95, 83}
  227.  
  228. {88, 88, 95, 83}
  229.  
  230. {92, 92, 95, 83}
  231.  
  232. {88, 92, 95, 83}
  233.  
  234. Question 12 (Multiple Choice Worth 2 points)
  235.  
  236. Suppose the following array is declared:
  237.  
  238. int[ ] grades = {88, 92, 95, 83};
  239.  
  240. What is the value of grades[grades[0] / 22]?
  241.  
  242. An ArrayIndexOutOfBoundsException occurs
  243.  
  244. 4
  245.  
  246. 88
  247.  
  248. 92
  249.  
  250. 95
  251.  
  252. Question 13 (Multiple Choice Worth 2 points)
  253.  
  254. What is printed by this code segment?
  255.  
  256. String s = "Howdy";
  257. int i = s.length() - 1;
  258. String total = "";
  259. String letter;
  260.  
  261. while (i >= 0)
  262. {
  263.     letter = s.substring (i, i + 1);
  264.     System.out.print (i + " " + letter + " ");
  265.     total = total + letter;
  266.     i--;
  267.     }
  268.  
  269. 4 H 3 o 2 w 1 d 0 y
  270.  
  271. 0 H 1 o 2 W 3 d 4 y
  272.  
  273. 4 y 3 d 2 w 1 o 0 H
  274.  
  275. 0 y 1 d 2 w 3 o 4 H
  276.  
  277. 0 1 2 3 4 H o w d y
  278.  
  279. Question 14 (Multiple Choice Worth 2 points)
  280.  
  281. The following code is intended to calculate the sum of the first five positive even
  282. integers.
  283.  
  284. int sum = 2, k;
  285.  
  286. for(k = 4; k <= 12; k += 2)
  287.  
  288. {
  289.  
  290. sum += k;
  291.  
  292. }
  293.  
  294. What is wrong with this code segment?
  295.  
  296. The segment calculates the sum of the first four positive even integers.
  297.  
  298. The segment calculates the sum of the first six positive even integers.
  299.  
  300. The segment calculates the sum of the first seven positive even integers.
  301.  
  302. The variable sum is incorrectly initialized. The segment would work correctly if sum
  303. was initialized to 0.
  304.  
  305. The segment works as intended.
  306.  
  307. Question 15 (Multiple Choice Worth 2 points)
  308.  
  309. Assume that a is an array of two or more integers, and that b and c are integers.
  310.  
  311. What is the result of the following code?
  312. c = 0;
  313. b = 1;
  314. if (a.length > 0) {
  315. c = a[0];
  316. }
  317. while (b < a.length){
  318. if (a[b] < c) {
  319. c = a[b];
  320. }
  321. b++;
  322. }
  323.  
  324. b contains the highest value in the array
  325.  
  326. b contains the lowest value in the array
  327.  
  328. c contains the highest value in the array
  329.  
  330. c contains the lowest value in the array
  331.  
  332. An endless loop occurs
  333.  
  334. Question 16 (Multiple Choice Worth 2 points)
  335.  
  336. Given the following code:
  337.  
  338. if (n == 2)
  339. {
  340.     k -= 2;
  341.     }
  342.     else if (n == 3)
  343.     {
  344.     k -= 3;
  345.     }
  346.  
  347.     can be rewritten as:
  348.  
  349.     if (< condition >) {
  350.     < assignment statement >;
  351.     }
  352.  
  353.     Assume that evaluating < condition > does not change the values stored in n and k. Which
  354.     of the following could be used as < assignment statement >?
  355.  
  356. k -= n;
  357.  
  358. k -= 1;
  359.  
  360. k -= 2;
  361.  
  362. k += n;
  363.  
  364. k = n – k;
  365.  
  366. Question 17 (Multiple Choice Worth 2 points)
  367.  
  368. Consider the following code segment:
  369.  
  370. int i;
  371. for (i = 0; i <= 10; i++) {
  372. if ((i % 3) == 1) {
  373. System.out.print(i + " ");
  374. }
  375. }
  376. What is printed as a result of executing this code segment?
  377.  
  378. 1 2 3 4 5 6 7 8 9 10
  379.  
  380. 1 3 5 7 9
  381.  
  382. 1 3 7 9
  383.  
  384. 1 4 7
  385.  
  386. 1 4 7 10
  387.  
  388. Question 18 (Multiple Choice Worth 2 points)
  389.  
  390. Suppose the following array is declared:
  391.  
  392. int[ ] grades = {88, 92, 95, 83};
  393. and the following integer is declared:
  394. int index = 1 + 6 % 3;
  395. What is the value of grades[index]?
  396.  
  397. An ArrayIndexOutOfBoundsException occurs
  398.  
  399. 88
  400.  
  401. 92
  402.  
  403. 95
  404.  
  405. 83
  406.  
  407. Question 19 (Multiple Choice Worth 2 points)
  408.  
  409. Given the following code:
  410.  
  411. int i = 100;
  412. int j = 10;
  413. while (i > 0)
  414. {
  415. i = i / j;
  416. j = 1 + j % 5;
  417. }
  418. What is the value of i after this code executes?
  419.  
  420. 0
  421.  
  422. 1
  423.  
  424. 2
  425.  
  426. 5
  427.  
  428. 10
  429.  
  430. Question 20 (Multiple Choice Worth 2 points)
  431.  
  432. Consider the following code, What are the values in array after the following code executes?
  433.  
  434. int[ ] array = new int[3];
  435. int index = 1;
  436. array[index] = index - 1;
  437. index++;
  438. array[index] = array[index - 1] - 1;
  439. array[index - 2] = index % 3;
  440.  
  441. {0, 0, 0}
  442.  
  443. {0, 0, 2}
  444.  
  445. {2, 0, 0}
  446.  
  447. {2, 0, -1}
  448.  
  449. {3, 0, 2}
  450.  
  451. Question 21 (Multiple Choice Worth 2 points)
  452.  
  453. If a, b, and c are boolean variables such that a is true, b is false, and c is true,
  454. which of these expressions:
  455.  
  456. I.!((a || b) && c)
  457. II.!a && (b && c)
  458. III.!a && (b || c)
  459. evaluates to false?
  460.  
  461. I only
  462.  
  463. II only
  464.  
  465. III only
  466.  
  467. II and III only
  468.  
  469. I, II, and III
  470.  
  471. Question 22 (Multiple Choice Worth 2 points)
  472.  
  473. What is output by the following program?
  474.  
  475. int i = 6;
  476. while (i >= 2) {
  477. System.out.print (i + " ");
  478. if ((i % 2) == 0) {
  479. i = i / 2;
  480. } else {
  481. i = i + 1;
  482. }
  483. }
  484.  
  485. 6 7 4 2
  486.  
  487. 6 3 4 2
  488.  
  489. 6 2 4 1
  490.  
  491. 6 5 4 3 2
  492.  
  493. 6 3 5 2
  494.  
  495. Question 23 (Multiple Choice Worth 2 points)
  496.  
  497. Consider the following two code segments. In both, assume that n is an integer
  498. variable that has been declared and initialized.
  499.  
  500. Segment 1
  501.  
  502. int prod = 1;
  503.  
  504. int i;
  505.  
  506. for (i = 2; i <= n; i++) {
  507.  
  508. prod *= i;
  509. }
  510.  
  511. System.out.println(prod);
  512.  
  513. Segment 2
  514.  
  515. int prod = 1;
  516.  
  517. int i = 2;
  518.  
  519. while (i <= n) {
  520.  
  521. prod = prod * i;
  522.  
  523. i++;
  524.  
  525. }
  526.  
  527. System.out.println(prod);
  528.  
  529. For which integer values of n do these code segments print the same result?
  530.  
  531. Only n > 1
  532.  
  533. Only n < 1
  534.  
  535. Only n == 1
  536.  
  537. Only n >= 1
  538.  
  539. Any integer n produces the same result
  540.  
  541. Question 24 (Multiple Choice Worth 2 points)
  542.  
  543. In the following algorithm, which constant should be assigned to maximum to ensure that the algorithm finds the largest integer?
  544.  
  545. maximum = <<constant>>;for(int current = 0; current < numbers.length; current ++){if (maximum < numbers[current])maximum = numbers[current];}
  546.  
  547. Int.MIN_VALUE
  548.  
  549. Int.MAX_VALUE
  550.  
  551. Integer.MAX_VALUE
  552.  
  553. Integer.MIN_VALUE
  554.  
  555. Question 25 (Multiple Choice Worth 2 points)
  556.  
  557. Assume that age has been declared as an int variable. Which expression is true
  558. whenever age indicates that the person is a teenager?
  559.  
  560. ((age < 20) && (age >= 13))
  561.  
  562. ((age < 20) || (age >= 13))
  563.  
  564. ((age <= 19) && (age < 13))
  565.  
  566. ((age <= 19) || (age >= 13))
  567.  
  568. ((age <= 19) && (age >= 12))
  569.  
  570. Question 26 (Multiple Choice Worth 2 points)
  571.  
  572. The Integer.MIN_VALUE constant has the value of ____.
  573.  
  574. -231
  575.  
  576. -231 - 1
  577.  
  578. -231 - 1
  579.  
  580. -231 + 1
  581.  
  582. YOU MUST CHECK THE BOX BELOW PRIOR TO SUBMITTING YOUR EXAM!
  583.  
  584. Check this box to indicate you are ready to submit your exam
  585.  
  586. Tutorial Explorer Compass Toolbox Calendar Notification Feature Security Workload Usage Users Group
  587.  
  588. You have 2 Unread E-Mail Messages
  589.  
  590. Current course:
  591.  
  592. Related Help Center Topics
  593.  
  594. Taking Exams
  595. Proctored Exams
  596. Question Types
Advertisement
Add Comment
Please, Sign In to add comment