본문 바로가기
자바(Java)/자바 AP

APCSA Mock Test

by 긱펀 2024. 3. 29.
반응형

APCSA Mock Test

 

 

-Mock Test (1) link: https://vo.la/vlsqd

 

-Mock Test (2) link: https://vo.la/bHyeQ

 

-Mock Test (3) link: https://vo.la/cWnxf

 

-Mock Test (4) link: https://vo.la/IkCne

 

-Mock Test (5) link: https://vo.la/NhlYl

 

-Mock Test (6) link: https://vo.la/XUvSl

 

(Timed test below;)

-Mock Test (7) link: https://vo.la/LPIuq

 

-Mock Test (8) link: https://vo.la/axuCw

 

-Mock Test (9) link: https://vo.la/EojTd

 

-Mock Test (10) link: https://vo.la/IDieV

 

-Mock Test (11) link: https://vo.la/VGhMZ

 

 

 


-Mock Test (1) 정답은 아래 "더보기"클릭

더보기

 

1.A

(Only when the search value is the first item in the array, and thus the first value encountered in sequential search, will sequential be faster than binary.)

 

2.E

(NOTing (negating) an OR expression is the same as the AND of the individual values NOTed (negated). See De Morgans laws.)

 

3.D

(This is the definition of encapsulation and this is done in Java using private (a member is directly accessible only in the class that defines it) and protected (a member is directly accessible only within code in the same package and in subclasses)

 

4.E

(When a contains a value equal to zero then multiplying that value by 2 will always be 0 and never make the result larger than the temp value (which was set to some value > 0), so an infinite loop will occur.)

 

5.B

(No matter what x is set to originally, the code will reset it to 0.)

 

6.E

(The add method that takes just a value as a parameter adds that value to the end of the list. The set replaces the value at that index with the new value. The add with parameters of an index and a value puts the passed value at that index and moves any existing values by one index to the right (increments the index). So the list looks like: 1 // add 1 1 2 // add 2 1 2 3 // add 3 1 2 4 // set index 2 to 4 1 2 5 4 // add 5 to index 2 (move rest right) 1 2 5 4 6 // add 6 to end)

 

7.A

(All of these are valid reasons to use an inheritance heirarchy.)

 

8.C

(This has a recursive call which means that the method calls itself when (x / 10) is greater than or equal to zero. Each time the method is called it prints the remainder of the passed value divided by 10 and then calls the method again with the result of the integer division of the passed number by 10 (which throws away the decimal part). After the recursion stops by (x / 10) == 0 the method will print the remainder of the passed value divided by 10 again.)

 

9.B

(The variable i loops from 1 to 6 and each time the values are as follows: i = 1, t = 10, a = 4, b = 9, i = 2, t = 4, a = 11, b =2, i = 3, t = 11, a = 5, b = 8, i = 4, t = 5, a = 12, b = 1, i = 5, t = 12, a = 6, b = 7, i = 6, t = 6, a = 13, b = 0)

 

10.C

(This code loops through the string printing 2 characters at a time. The last time through the loop the index is test.length() - 2.)

 

11.A

(The loop starts with var1=0 and var2=2. The while checks that var2 isn't 0 (2!=0) and that var1 / var2 is greater than or equal to zero (0/2=0) so this is equal to zero and the body of the while loop will execute. The variable var1 has 1 added to it for a new value of 1. The variable var2 has 1 subtracted from it for a value of 1. At this point var1=1 and var2=1. The while condition is checked again. Since var2 isn't 0 (1!=0) and var1/var2 (1/1=1) is >= 0 so the body of the loop will execute again. The variable var1 has 1 added to it for a new value of 2. The variable var2 has 1 subtracted from it for a value of 0. At this point var1=2 and var2=0. The while condition is checked again. Since var2 is zero the while loop stops and the value of var1 is 2 and var2 is 0.)

 

12.B

(Susan is 5 years older than Matt so s == m + 5 should be true and in 3 years she will be twice as old so s + 3 = 2 * (m + 3) = 2 * m + 6.)

 

13.D

(When you create a 2d array the first value is the number of rows and the second is the number of columns. This code will put a 1 in the array when the row index is less than the column index and a 2 in the array when the row and column index are the same, and a 3 in the array when the row index is greater than the column index.)

 

14.E

(Strings are immutable meaning that any changes to a string creates and returns a new string, so the string referred to by s1 does not change)

 

15.B

(The while loop will iterate 8 times. The value of num each time through the loop is: 0, 2, 4, 6, 8, 10, 12, and 14. The corresponding remainder operator of 3 is: 0, 2, 1, 0, 2, 1, 0, 2, which is print to the console.)

 

16.D

(The variable lenCount is incremented each time the current array element is the same value as the target. It is never reset so it counts the number of occurrences of the value target in nums. The method returns maxLen which is set to lenCount after the loop finishes if lenCount is greater than maxLen.)

 

17.E

(The statement a[1]--; is the same as a[1] = a[1] - 1; so this will change to 3 to 2. The return (a[1] * 2) does not change the value at a[1].)

 

18.D

(Choice I uses multiple if's with logical ands in the conditions to check that the numbers are in range. Choice Choice II won't work since if you had a score of 94 it would first assign the grade to an "A" but then it would execute the next if and change the grade to a "B" and so on until the grade was set to a "C". Choice III uses ifs with else if to make sure that only one conditional is executed.)

 

19.D

(This will update the hours and minutes correctly. It will add the floor of the division of minutes by 60 to hours and then set minutes to the remainder of the division of minutes by 60.)

 

20.C

(Even though b is declared as type Base it is created as an object of the Derived class, so all methods to it will be resolved starting with the Derived class. So the methodOne() in Derived will be called. This method first calls super.methodOne so this will invoke the method in the superclass (which is Base). So next the methodOne in Base will execute. This prints the letter "A" and invokes this.methodTwo(). Since b is really a Derived object, we check there first to see if it has a methodTwo. It does, so execution continues in Derived's methodTwo. This method invokes super.methodTwo. So this will invoke the method in the super class (Base) named methodTwo. This method prints the letter "B" and then returns. Next the execution returns from the call to the super.methodTwo and prints the letter "D". We return to the Base class methodOne and return from that to the Derived class methodOne and print the letter "C".)

 

 


 

728x90
반응형

댓글