AP Comp Sci 2015 A answers

Ace your homework & exams now with Quizwiz!

Assume that x and y are boolean variables and have been properly intialized. Which of the following always evaluates to the same value as the expression above?

(A) x

for (int r = 3; r > 0; r--) What is printed as a result of executing the code segment?

(A)--* -** ***

Assume that int val has been declared and intialized with a value that satisifies the precondition of the method. Which of the following best describes the value returned by the call what(val)?

(A)The number of digits in the decimal representation of val is returned

int [ ] [ ] numbers = {{1, 2, 3} {4, 5, 6}}; Which of the following code segments produces the output 123456?

(A)for (int [ ] row :numbers) { for ( int n : row) { System.out.println(n); }

Assume that sort is called with the array{6, 3, 2, 5, 4, 1}. What will the value of data be after three passes of the outer loop( i.e when j = 2 at the point indicated by /* End of outer loop*/)?

(B){1, 2, 3, 5, 4, 6}

public static int [ ] operation (int [ ] [ ] matrix, int r, int c) Which of the following represents the contents of arr as a result of executing the code segment?

(B){1, 6, 3, 4}

Which of the following methods can be added to the SomeMethods class without causing a comple-time error? I. public void one(int value) II. public void one (String first, int second) III. public void one (int first, int second, int third)

(D)II and III only

public static void whatsItDo (String str) What is printed as a result of the call whatsItDo("WATCH")?

(D)WATC WAT WA W

Assume that nums has been declared and initialized as an array of integer values. Which of the following best describes the value returned by the call mystery(nums) ?

(E) An index of a value that occurs most often in nums

public static boolean containsArt(String s1, String s2, String s3) Which of the following method calls demonstrates that the method does not work as intended?

(A) containsArt ("rattrap", "similar", "today")

Which of the following can be used to replace /* condition */ so that numDivisors will work as intended?

(A) inputVal % k ==0

Assume that numbers has been initialized with the following values. {17, 34, 21, 42, 15, 69, 48, 25, 39}. Which of the following represents the order of the values in numbers as a result of the call mystery(3)?

(A){17, 20, 21, 42, 45, 69, 48, 51, 39}

What is printed as a result of executing the following code segment? A obj = new B( ); obj.show ( );

(B) B

Assume that x and y are boolean variables and have been properly initialized. Which of the following best describes the result of evaluation the expression above?

(B) false always

Assume that sort is called with the array {1, 2, 3, 4, 5, 6}. How many times will the expression indicated by /* Compare values */ and the statement indicated by /* Assign to temp*/ execute?

(B)15, 5

Which of the following code segments can be used to replace /* missing code */ so that method getCost will work as intended? I. if (numBoxes >= 10) II. if (numBoxes >=10) III. if (numBoxes > 0)

(B)II only

public class StudentInfo Which of the following could be used to replace /* missing code */ so that averageAgeInMajor will compile without error?

(B)if (theMajor.equals(k.getMajor())) { sum += k.getAge(); count++; }

Method findMax is intended to return the largest value in the array arr. Which of the following best describes teh conditions under which the method findMax will not work as intended?

(C) The largest value in arr is negative

int count = 0; for (int x = 0, x<4; x++) What is printed as a result of executing the code segment?

(C)10

for(int outer = 1; outer <=6; outer++) What will be printed as a result of executing the code segment?

(C)2 4 6 2 4 6 4 6 4 6 6 6

Consider the following method biggest, which is intended to return the greatest of three integers. It does not always work as intended. Which of the following best describes the error in the method?

(C)biggest may not work correctly when a and b have equal values

Assume that array arr has been defined and initialized with the values {5, 4, 3, 2, 1}. What are the values in array arr after two passes of the for loop(i.e. when j = 2 at the point indicated by /* end of for loop */)?

(C){3, 4, 5, 2, 1}

public static int doWhat(int num) Which of the following best describes the value returned from a call to doWhat?

(D) The sum of all odd integers between 1 and num , inclusive

System. out. println(404 / 10 * 10 +1); What is printed as a result of executing the following statement?

(D)401

public interface Student { /* implementation not shown */} Assume that each class has a zero-parameter constructor. Which of the following is NOT a valid declaration?

(D)Student d = new Athlete();

public static void start() What is printed as a result of the start( )?

(E)1 2 3 4 5 6 blackboard

Which of the following replacements for /* missing code */ would best simulate the value produced as a result of rolling two number cubes?

(E)2 + (int) (math.random () * 6) + (int) (Math.random() * 6)

I. x<0 II. x<=1 III. x<10 For which of the conditions will nothing be printed?

(E)I, II, and III

Which of the following represents board after this code segment is executed?

(E)Picture that looks like two diagnols going left to right

public static int calculate (int [ ] [ ] values) Which of the following best describes what is returned by the calculate method?

(E)The column index of an element with the largest value in the two-dimensional array

public static boolean mystery(String str) { String temp = "" Which of the following calls to mystery will return true?

(E)mystery("noon"


Related study sets

UFL Investments: Ch 20-23 Quizzes sam

View Set

Colorado Life - Completing the Application, Underwriting, and Delivering the Policy

View Set

Fundamentals Nursing Prep U Chapter 13 Outcome Identification and Planning

View Set

English Unit:5 Lesson:7 "Alone," "The Nobel Prize," and "First Frost"

View Set

اجتماعيات للصف التاسع منهج كويتي

View Set

Biology for Nursing Practice SEM1

View Set