Download presentation
Presentation is loading. Please wait.
Published byConrad Payne Modified over 9 years ago
1
AP Practice Questions Question #1 KX-inX-out 003 234 445 657 8>7 Quit loop Answ er: C
2
AP Practice Questions Question #2 2. Answer: E If d2>d1, then d1 – d2 is negative (< tolerance), even if they are more than tolerance apart. E is the only answer that takes this into account
3
AP Practice Questions Question #3 3. KArr inArr out 312345671235567 4 1235667 5 1235677
4
AP Practice Questions Question #4 4. A is the correct answer B does not match method header C tries to access an object’s private var from outside the object D References the type rather than the object E Does not match the method header
5
AP Practice Questions Question #5 5. B: is correct A: this would allow modification C: private method would not be accessible to other classes D and E: Integers are passed by value. The variable x would not be changed when the method returned.
6
6. AP Practice Questions Question #6 KSeq- in Seq- out 1Null4 247 3712 4 19 5 28 6 39 Note: You know it’s C after first loop. Only c begins with 4
7
7. AP Practice Questions Question #7 KOutput- in Output-out 1“”o 3oop 5 opt 7 Optr CCC Note: input.substring(1,2) returns “o”;
8
8. AP Practice Questions Question #8 KPrint 00 7 1 20 7 2 5 30 7 2 5 3 3 4 Answer: B
9
9. AP Practice Questions Question #9 I.If data contains a single element = 5. The first if statement returns 0, which is OK. II.If data does not contain a 5, then last-1 will eventually reach zero, causing an error III.Multiple 5’s are OK. The method will just return the first one. Answer: B
10
10. AP Practice Questions Question #10 B is correct A: you will return before testing data[0] C: You are checking from back by decrementing last. After the first call it will be < data.length D: Same problem as C E: Avoids the error, but you never return anything.
11
AP Practice Questions Question #11 11. Math.random() generates random numbers between 0 and 1 (non-inclusive). Suppose myList.size() = 8. Math.random()*8 generates random numbers between 0 and 8 (non-inclusive). Casting (int) makes these integers 0 to 7. Answer: B
12
AP Practice Questions Question #12 !(a != b) a = b so !(!(a != b) && (b > 7)) !((a = b) && (b>7)) (a !=b) || (b<=7) Answer: B 12.
13
AP Practice Questions Question #13 Answer: E j starts at the beginning and k starts at the end. They swap values until they meet in the middle. 13.
14
14. AP Practice Questions Question #14 Code prints 4 8 12 16 … A prints out 1-25 B prints out 1 5 9 … C prints out 1 2 3 0 1 2 … D prints out 4 16 E Correct
15
15. AP Practice Questions Question #15 A, B, D: We are looking for the Actor’s direction, not the loc or the grids. C: Can’t cast loc to Actor E: The grid is getting something at a certain location and returning it’s direction. We’ll assume that something is an Actor, and this works.
16
16. AP Practice Questions Question #16 The critical piece of information here is that the ColorChangingCritter does not change direction. Moves without changing direction II.Unless you override their methods, Critters turn, so a call to the super lass causes a turn. III.Sets the direction to the original direction, so OK. answer: d
17
17. AP Practice Questions Question #17 substring(4, 8) = “iler” substring(0,3) = “com” returns “ilercom answer C
18
18. AP Practice Questions Question #18 Answer C you multiply n by itself k times
19
19. AP Practice Questions Question #19 k is never incremented, so it is always < 4 infinite loop. When they bother to put an infinite loop answer choice, check for one closely!
20
20. AP Practice Questions Question #20 recur(27) calls recur(9) 9<10 return 9*2 = 18 College board had wrong answer! I coded and ran it to double-check.
21
21. AP Practice Questions Question #21 WhatsItDo(“Watch”) after four recursive calls stack looks like this: W Wa Wat Watc Watch As each recursive call returns the print statement is executed: W Wa Wat Watc Note that “Watch” was not printed. You would need a statement after the original call for that to occur.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.