+ All Categories
Home > Documents > AP Practice Questions Question #1 KX-inX-out 003 234 445 657 8>7 Quit loop Answ er: C.

AP Practice Questions Question #1 KX-inX-out 003 234 445 657 8>7 Quit loop Answ er: C.

Date post: 01-Jan-2016
Category:
Upload: conrad-payne
View: 219 times
Download: 1 times
Share this document with a friend
21
AP Practice Questions AP Practice Questions Question #1 Question #1 K X- in X- out 0 0 3 2 3 4 4 4 5 6 5 7 8>7 Qui t loo p Ans wer : C
Transcript

AP Practice QuestionsAP Practice QuestionsQuestion #1Question #1

K X-in X-out

0 0 3

2 3 4

4 4 5

6 5 7

8>7Quit loop

Answer: C

AP Practice QuestionsAP Practice QuestionsQuestion #2Question #2

2.

Answer: EIf d2>d1, then d1 – d2 is negative (< tolerance), even if they are more than tolerance apart. E is the only answer that takes thisinto account

AP Practice QuestionsAP Practice QuestionsQuestion #3Question #3

3.K Arr in Arr out

3 1234567 1235567

4 1235567 1235667

5 1235667 1235677

AP Practice QuestionsAP Practice QuestionsQuestion #4Question #4

4.

A is the correct answerB does not match method headerC tries to access an object’s private var from outside the objectD References the type rather than the objectE Does not match the method header

AP Practice QuestionsAP Practice QuestionsQuestion #5Question #5

5.

B: is correctA: this would allow modificationC: private method would not be accessible to other classesD and E: Integers are passed by value.

The variable x would not be changed when the method returned.

6.

AP Practice QuestionsAP Practice QuestionsQuestion #6Question #6

K Seq-in

Seq-out

1 Null 4

2 4 7

3 7 12

4 12 19

5 19 28

6 28 39Note: You know it’s C after first loop. Onlyc begins with 4

7.

AP Practice QuestionsAP Practice QuestionsQuestion #7Question #7

K Output-in

Output-out

1 “” o

3 o op

5 op opt

7 opt Optr

C C C

Note: input.substring(1,2) returns “o”;

8.

AP Practice QuestionsAP Practice QuestionsQuestion #8Question #8

K Print

0 0 7

1 0 7

2 0 7 2 5

3 0 7 2 5 3 3

4 0 7 2 5 3 3

Answer: B

9.

AP Practice QuestionsAP Practice QuestionsQuestion #9Question #9

I. If data contains a single element = 5. The firstif statement returns 0,

which is OK.II. If data does not contain

a 5, then last-1 willeventually reach zero, causing an error

III. Multiple 5’s are OK. Themethod will just return the first one.

Answer: B

10.

AP Practice QuestionsAP Practice QuestionsQuestion #10Question #10

B is correctA: you will return before testing data[0]C: You are checking from back by decrementing last. After the first call it will be < data.lengthD: Same problem as CE: Avoids the error, but you never return anything.

AP Practice QuestionsAP Practice QuestionsQuestion #11Question #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

AP Practice QuestionsAP Practice QuestionsQuestion #12Question #12

!(a != b) a = bso !(!(a != b) && (b > 7))!((a = b) && (b>7))(a !=b) || (b<=7)

Answer: B

12.

AP Practice QuestionsAP Practice QuestionsQuestion #13Question #13

Answer: Ej starts at the beginning and k starts at the end. They swap values until they meet in the middle.

13.

14.

AP Practice QuestionsAP Practice QuestionsQuestion #14Question #14

Code prints4 8 12 16 …

A prints out 1-25B prints out 1 5 9 …C prints out 1 2 3 0 1 2 …D prints out 4 16E Correct

15.

AP Practice QuestionsAP Practice QuestionsQuestion #15Question #15

A, B, D: We are looking for the Actor’s direction, not the loc or the grids. C: Can’t cast loc to ActorE: 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.

AP Practice QuestionsAP Practice QuestionsQuestion #16Question #16

The critical piece of information here is that theColorChangingCritter doesnot change direction.

• Moves without changingdirection

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.

AP Practice QuestionsAP Practice QuestionsQuestion #17Question #17

substring(4, 8) = “iler”substring(0,3) = “com”

returns “ilercom

answer C

18.

AP Practice QuestionsAP Practice QuestionsQuestion #18Question #18

Answer C

you multiply n by itself k times

19.

AP Practice QuestionsAP Practice QuestionsQuestion #19Question #19

k is never incremented, soit is always < 4 infinite loop.

When they bother to putan infinite loop answer choice, check for one closely!

20.

AP Practice QuestionsAP Practice QuestionsQuestion #20Question #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.

AP Practice QuestionsAP Practice QuestionsQuestion #21Question #21WhatsItDo(“Watch”)

after four recursive calls stack looks like this:

WWaWatWatcWatch

As each recursive call returns the print statement is executed:WWaWatWatc

Note that “Watch” was not printed. You would need a statement after the original call for that to occur.


Recommended