Description

CSAP Review – 100 Sample Multiple Choice Questions 1. Object Oriented Programming (A) (B) (C) (D) 2. makes programs more reliable.simulates real life. uses a lot of intimidating vocabulary, which is not as bad as it sounds. is all of the above. The actions in a Java class are called (A) (B) (C) (D) procedures. functions. methods. subroutines. 3. Which of the following Math class features do not use any parameters or arguments? (A) (B) (C) (D) PI E final Both A and B 4. What is the value of result in the following statement? int result = Math.pow(3,4); (A) (B) (C) (D) 12 81 64 4 For questions 5-8 use the following Bank class information. It contains the headings of the methods in the Bank class, along with a description. public Bank() // default constructor starts checking and savings account with zero dollars. public Bank(double c, double s) // parameter creates an object with c dollars in checking and s dollars in savings. public double getChecking() // returns the checking account balance public double getSavings() // returns the savings account balance public double getCombined() // returns the combined balance of the checking and savings account public void changeChecking(double amount) // alters the balance of the checking account by the amount parameter public void changeSavings(double amount) // alters the balance of the savings account by the amount parameter public void closeChecking() // alters the checking account balance to zero public void closeSavings() // alters the savings account balance to zero 5. The methods in the Math class are (A) (B) (C) (D) class methods. object methods. expression methods. variable methods. 6. The methods in the Bank class are (A) (B) (C) (D) class methods. object methods. expression methods. variable methods. 7. Access to methods of the Bank class requires (A) (B) (C) (D) 8. using a statement, like Bank.getSavings(); using a statement, like Bank.getSavings; the creation of one or more Bank objects. using the get method. What is the output of the following program segment? Bank tom; tom = new Bank(); Bank sue; sue = new Bank(); tom.changeChecking(1000); sue.changeChecking(1500); System.out.println("sue: " + sue.getSavings()); System.out.println("tom: " + tom.getSavings()); (A) (B) (C) (D) tom: sue: sue: 1000.0 sue: 1500.0 1500.0 tom: 1000.0 0.0 tom: 0.0 Error message 9. Assume that rand is an object of the Random class. Which of the following statements generates a random integer in the [400..1600] range? (A) (B) (C) (D) int number = rand.nextInt(1600) + 400; int number = rand.nextInt(1200) + 400; int number = rand.nextInt(1600); int number = rand.nextInt(1201) + 400; 10. The kind of output created by an object of the DecimalFormat class is determined by (A) object. (B) (C) (D) the type of parameter used with the construction of a new DecimalFormat using the format method. using the output method. all of the above. 11. A conditional statement is 0. System.println("The End"). any program statement with an unary operator.0 The End Bonus: 500. double sales = 200000. (A) (B) (C) (D) Bonus: 50. What is the output of the following program segment? double bonus = 500. System. double sales = 200000.0) System.out.0 The End Bonus: 750.out. any program statement with a binary operator.out.0.0.println("Bonus: " + bonus). a program expression that evaluates to true or false. System. if (sales >= 300000.0 The End Bonus: 500. double sales = 200000.0.0. if (sales >= 300000.(A) (B) (C) (D) 12. a program statement that requires input from the keyboard. .0 The End Bonus: 750.out.0 The End No output 13. System.0.0 The End No output 14.0) bonus += 250.0.0) bonus += 250. What is the output of the following program segment? double bonus = 500.println("The End"). (A) (B) (C) (D) Bonus: 50. if (sales >= 300000.out.println("Bonus: " + bonus).0. What is the output of the following program segment? double bonus = 500.println("Bonus: " + bonus). (A) (B) (C) (D) 16.0 (D) No output What is the output of the following program segment? int n1 = 100. int num = 100. } System. } else { n1 = n2. int n3 = n1 / n2.0 (C) Bonus: 750. n2 = n1. switch(qwerty) { case 'A': num ++.out. 100 200 200 100 200 100 200 100 15. case 'B': num += 2. int n2 = 200. n1 = n2. case 'C': num += 3. What is the value of num at the conclusion of the following program segment? char qwerty = 'B'. (A) Bonus: 250. } .0.0 (B) Bonus: 500. if (n3 > 0) { n2 = n1.println(n1 + " " + n2).bonus += 250. case 'D': num += 4. k < 100. (A) (B) (C) (D) 99 100 101 102 19. switch(qwerty) { case 'A': num ++. k++) count++. case 'C': num += 3. What is the output of the following program segment? int count = 1. break. 100 102 109 Error message What is the value of num at the conclusion of the following program segment? char qwerty = 'B'. int num = 100. case 'D': num += 4.(A) (B) (C) (D) 17. break. case 'B': num += 2. break.println(count).out. for (int k = 0. What is the output of the following program segment? . } (A) (B) (C) (D) 100 101 102 Error message 18. System. k < 9. k++) { count1++. 6 7 6 7 7 8 3 3 What is the output of the following program segment? int sum = 0. count2++. k+=2) sum += k. num2 = num3.int count1 = 1.out. int num3 = 0. else { num1 = num2. if (num3 == 0) System.println("sum: " + sum). (A) (B) (C) (D) sum: 8 sum: 9 sum: 16 sum: 25 21. System. (A) (B) (C) (D) 20. for (int k = 1.out. } System. k <= 5. int count2 = 2. do { num3 = num1 % num2.println(num2). What is the output of the following program segment? int num1 = 120.println(count1 + " " + count2).out. for (int k = 0. } } while (num3 != 0). (A) (B) 0 6 . int num2 = 108. What is the output of the following program? public class Q39 { public static void main(String args [ ]) { method1().println("Calling method 3"). method3(). 12 36 A class method call (A) (B) (C) (D) requires that the class identifier precedes the method identifier.out.out. 23. } public static void method2() { System. } public static void method1() { System. method2(). } public static void method3() { System. } } (A) Calling method 1 Calling method 2 Calling method 3 Calling method 1 Calling method 3 Calling method 2 (B) . may be called with the method identifier only in certain circumstances.println("Calling method 2").println("Calling method 1"). uses the class identifier only for readability.(C) (D) 22. is only possible after a new object is constructed.out. } public static void method1(int n) { System. What is the output of the following program? public class Q41 { public static void main(String args [ ]) { method1(1). } public static void method3(int n) { System. } } (A) Calling method 1 Calling method 2 Calling method 3 Calling method 1 Calling method 3 Calling method 2 (B) . } public static void method2(int n) { System.println("Calling method " + n). method2(3).(C) method 1 method 3 method 2 Error message (D) 24.out.println("Calling method " + n).out.println("Calling method " + n).out. method3(2). } public static void method2(int n) { System.out.method2(int n = 2).println("Calling method " + n).out. Q42. } public static void method3(int n) { System. } public static void method1(int n) { System.method1(int n = 1 ).out.println("Calling method " + n).(C) method 1 method 3 method 2 Error message (D) 25.method3(int n = 3). What is the output of the following program? public class Q42 { public static void main(String args [ ]) { Q42.println("Calling method " + n). } } (A) Calling method1 Calling method2 Calling method3 Calling method1 Calling method3 Calling method2 method1 method2 (B) (C) . Q42. } public static void div(int p.y)). System.out. int y = 10.println(Calc. } } class Calc { public static void add(int p.sub(x.println(p + " / " + q + " = " + result). int q) { int result = p .out. System. System.println(p + " * " + q + " = " + result). int q) { int result = p + q. int q) { int result = p * q.10 25 * 10 (B) 25 + 10 = 35 25 .y)).out. Error message What is the output of the following program? public class Q44 { public static void main(String args [ ]) { int x = 25.println(Calc. System.q.out.out.add(x.10 = 15 25 * 10 = 250 (C) 35 15 250 .println(p + " .div(x. System.mul(x.method3 (D) 26. int q) { int result = p / q.println(Calc.out. System. System. } } (A) 25 + 10 25 .out.out." + q + " = " + result). } public static void sub(int p.println(Calc.println(p + " + " + q + " = " + result). } public static void mul(int p.y)).y)). System. 31. tom = new Piggy. it is not necessary to pass information to the methods. Which of the following statements shows correct syntax to create an object of the Piggy class? (A) (B) (C) (D) Piggy new tom = Piggy(). Object methods are typically used when (A) (B) (C) (D) only a single copy of the class needs to be loaded multiple copies or instances of a class are required. Error message 25 / 10 = 2 2 Class methods are typically used when (A) (B) (C) (D) only a single copy of the class needs to be loaded multiple copies or instances of a class are required. Piggy tom = new Piggy(). Calling a class method requires using (A) (B) (C) (D) a class identifier followed by a dot and a method identifier. Piggy = new tom(). a method that accesses class attributes.26 / 10 (D) 27. 32. only return methods are used in a class. another word for a class. 28. a method identifier followed by a dot and a class identifier. An object is (A) (B) (C) (D) one instance of a class. only return methods are used in a class. an object identifier followed by a dot and a method identifier. a class with static methods. . 29. a method identifier followed by a dot and a class identifier. an object identifier followed by a dot and a method identifier. 30. Calling an object method requires using (A) (B) (C) (D) a class identifier followed by a dot and a method identifier. a method identifier followed by a dot and an object identifier. it is not necessary to pass information to the methods. a method identifier followed by a dot and an object identifier. (B) A second constructor with the same constructor heading as the first constructor. available to methods of the same class and other classes.33. which is called automatically during the instantiation of a new object. What is an overloaded constructor? (A) A constructor with too many program statements. (D) is a parameter method. (B) is a parameter method. Access to private data or private methods is (A) (B) (C) (D) restricted to methods of the same class. which is called automatically during the instantiation of a new object. A default constructor (A) is a no-parameter method. A parameter constructor (A) is a no-parameter method. which is called automatically during the instantiation of a new object. When is a constructor called? (A) (B) (C) (D) Each time the constructor identifier is used in a program statement During the instantiation of a new object During the construction of a new class At the beginning of any program execution 34. (B) is a parameter method. (C) is a no-parameter method. 37. . (C) A second constructor with a different identifier than the first constructor. using features from an existing class. which is called automatically during the instantiation of a new object. 36. (C) is a no-parameter method. not an issue because the program will not compile. 35. restricted to methods of other classes. Inheritance is the process of (A) (B) using classes in the established standard Java Language library. 38. (D) is a parameter method. (D) A second or other multiple constructor with a different signature than any other constructor. a static class. which can use all the features of an established class. (C) Use the super keyword followed by the superclass identifier. inside the same module. How is information passed from the subclass constructor to the superclass constructor? (A) The superclass constructor is automatically called before the subclass constructor. Which identifier shows up both in the superclass and the subclass? (A) (B) (C) (D) The superclass identifier The subclass identifier The class identifier containing the main method The constructor identifier 42. a logic error will result. 41. A class. An established class. only if the primary program class is declared public. (D) Use the new operator inside the subclass constructor to instantiate the superclass. a subclass.(C) combining data and the methods. is (A) (B) (C) (D) a static class. which process the data. overloaded. 44. (B) Use the super keyword followed by a parameter list for the superclass. A subclass has access to the data attributes of a superclass (A) (B) (C) (D) if the superclass data is declared protected. a superclass. in all cases due to inheritance.. if the superclass data is declared private or protected. . overloaded. 43. whose members can all be used by a newly declared class. a subclass. 39. is (A) (B) (C) (D) 40. (A) (B) a compile error message will result. (D) dividing a program into multiple related files for each class in the program. If a subclass has the same method identifier as a superclass method. a superclass. only when B is true. the subclass method will be used. Which of the following columns is the correct truth table for (A or B) and B ? A T T F F B T F T F (A) T T T T (B) T F T F (C) T T F F (D) F F T T (E) F T F T 46. The Boolean expression A >= B is equivalent to which of the following expressions? (A) (B) (C) (D) (E) not (A > B) not (B >= A) not (A < B) A != B A <= B 48. Which of the following columns is the correct truth table for (A or B) or A ? A T T F F B T F T F (A) T T T T (B) T F T F (C) T F F F (D) F F T T (E) T T T F 47.(C) (D) 45. for all values of A and B. the superclass method will be used. only whenever both A is true and B is true. whenever either A is true or B is true. The Boolean expression (A and B) or A is true (A) (B) (C) (D) (E) only when A is true. The Boolean expression A > B is equivalent to which of the following expressions? (A) (B) (C) (D) (E) not (B > A) not (A <= B) not (A != B) B>A B >= A 49. The Boolean expression (A && B) && !(A && B) evaluates to . 50. must execute some process at least one time. The for loop is ideal for loop structures that (A) (B) (C) (D) repeat some process a fixed number of times. true whenever only A is true or only B is true. do all of the above. b.while loop is ideal for loop structures that (A) (B) (C) (D) repeat some process a fixed number of times. must check the loop condition before the loop body is executed. What is the output of the program segment below? int a. must check the loop condition before the loop body is executed. (A) (B) 1000 2000 . false in all cases.print(b). 53. if (a > 100) { if (a < 50) b = 1000.. 52. true in all cases. do all of the above. } else { if (a > 150) b = 2000. a = some mystery int. true whenever either A is true or B is true. The do. true whenever both A is true and B is true. else b = 3000. } System. else b = 3000. must execute some process at least one time.out.(A) (B) (C) (D) (E) 51. What is the last output by the following program segment? int x. x++. n = 5. .print("&"). while (y < 3) { y++. How many ampersands (&) are displayed by the program segment below? int n. p.(C) (D) 54. System.out. } } (A) (B) (C) (D) 4 5 6 7 55. System. p = 1. } while ( p < n). do { q = p. y. x = 1.out.println(x + y). } p += 2. while (q < n) { q += 2. 3000 The value of b cannot be determined without knowing the value of a. while (x < 3) { y = 1. q. 'N' or 'n'. int grade do { ( prompt and get user input for grade ) } while (grade < 0 || grade > 100). The user is prompted in some manner to enter 'Y'. You want this program to prevent the user from entering any grades that are outside the range of [0. (A) (B) (C) (D) (E) I only II only I & II only II and III only I and III only 57. 'y'. 1 2 3 5 Assume that you are writing a program.. where Y means to repeat the . int grade do { ( prompt and get user input for grade ) } while ( !(grade < 0) || !(grade > 100) ). II.(A) (B) (C) (D) 56.100]. int grade do { ( prompt and get user input for grade ) } while ( !(grade >= 0 && grade <= 100) ). III. Which of the following program segments will only accept the desired input? I. which repeats until user input states to stop. which will enter grades and average them. Assume that you are executing a program segment. program segment and N means to stop execution. do { ( prompt user and get input for choice ) notOK = (choice != 'Y' && choice != 'y' && choice != 'N' && choice != 'n'). char choice. (A) (B) (C) (D) (E) 58. } while (notOK). Which of the following program segments will only accept the desired input I. II. do { ( prompt user and get input for choice ) ok = (choice == 'Y' || choice == 'y' || choice == 'N' || choice == 'n'). do { ( prompt user and get input for choice ) notOK = (choice != 'Y' || choice != 'y' || choice != 'N' || choice != 'n'). . boolean notOK. II and III with a combination of Computer colors are created ____________________________ values. } while (!ok). III. boolean notOK. boolean ok. I only II only III only I and II only I. } while (notOK). char choice. char choice. (A) (B) (C) (D) 59. list = new int[100]. public class Java1314 . Both Segment1 and Segment2 declare list correctly. of the same or different data types. called fields. or more. Which of the following is a true statement about the comparison of Segment1 and Segment2? (A) (B) (C) (D) 62. green and white An array is a (A) data structure with one. Segment1 declares list incorrectly. red. green and blue red. which allows transfer between internal and external storage. list = new int[100]. Segment1 declares list correctly. or more. Segment2 declares list correctly.java below. yellow and blue blue. elements. (D) data structure with one. Segment2 list[] = new int[100]. Both Segment1 and Segment2 declare list incorrectly. Consider the two program segments below. Segment2 declares list incorrectly. 60. green and yellow blue. int list[]. (B) data structure with LIFO access. Segment1 int list[]. Consider the program segment below. What is the output of program Java1314. elements of the same type. How many integers can be stored in the list array (A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution 61. (C) data structure. 3. k++) System.println("list[" + k + "] = " + list[k]). p++) { . } } (A) list[0] = 0 list[1] list[2] list[3] list[4] list[0] = 1 list[1] list[2] list[3] list[4] list[1] = 1 list[2] list[3] list[4] list[5] = = = = = = = = = = = = 1 2 3 4 2 3 4 5 2 3 4 5 (B) (C) (D) list[1] = 2 list[2] = 3 list[3] = 4 list[4] = 5 Compile Error (E) 63. What is the output of the program below? public class Java1326 { public static void main(String args[]) { int matrix[ ][ ]. for (int k = 1.{ public static void main(String args[]) { int list[] = {1.5}. p < 3.out. for(int p = 0.4. matrix = new int[3][4].length. k < list.2. print(matrix[p][q] + " "). } } (A) 0 0 0 0 0 0 0 0 0 0 0 0 Compile Error (B) 0 0 0 0 0 0 0 0 0 0 0 0 (C) 0 0 0 0 0 0 0 0 0 0 (D) 64. What is the output of the program below? public class Java1327 { public static void main(String args[]) { int matrix[ ][ ].out. .for(int q = 0.println(). System. q < 4. System.println().print(matrix[q][p] + " ").out.out.out. p < 3.println(). q < 4. manageable program modules. } } (A) 0 0 0 0 0 0 0 0 0 0 0 0 Error message (B) 0 0 0 0 0 0 0 0 0 0 0 0 (C) 0 0 0 0 0 0 0 0 0 0 (D) 65. q++) System. matrix = new int[3][4]. __________ is the principle of breaking up a program into smaller. p++) { for(int q = 0.out. q++) System.println(). } System. } System. for(int p = 0.out. polymorphism. class variables that store information. 71. Object Oriented Programming is characterized by using (A) (B) (C) encapsulation. Methods are (A) (B) (C) (D) action modules that process data. is one instance of a more general data type. combines both data and the methods that act upon the data. 69. The data in a class are also called (A) (B) (C) (D) attributes. a program is ready for execution. Encapsulation Inheritance Polymorphism Divide and conquer is a user-defined data type. none of the above. An object (A) (B) (C) (D) is a user-defined data type. inheritance. a program compiles correctly. instances of a class.(A) (B) (C) (D) 66. combines both data and the methods that act upon the data in the same module. 70. is both A and B. is both A and B. Instantiation is the moment that (A) (B) (C) (D) memory is allocated for a specific object of a class. which is a member of a class. 68. all of the above. memory is allocated for a specific object. A class (A) (B) (C) (D) 67. instance variables. . fields. is one instance of a more general data type. the initial value of the simple data type's variable is copied. the initial values of the object instantiation information are copied. 76. period during which an object is defined and allocates memory to store values. . all of the above. neither a void method nor a return method. (A) (B) (C) (D) the actual current value of the simple data type's variable is copied. requires using the new operator as well as one String parameter. (B) storing information in private data fields. When simple data types are used for parameter passing. a new object of the same class as the parameter object is instantiated. the memory reference where the object information is stored is copied. (D) testing a program without using any actual data. all of the above. The creation of a String object (A) (B) (C) (D) requires the new operator. 75. (A) (B) (C) (D) the current values of the data attributes of the object are copied.(D) 72. is always done without the new operator. called during the instantiation of a new object. Information hiding is the concept of (A) declaring all significant data as private. can be done with or without the new operator. range of accessing member methods. 77. A constructor is (A) (B) (C) (D) a method with the same identifier as the class identifier. a new object of the data type is instantiated. (C) thinking about programming features without concern about the implementation of these features. 74. 73. When objects are used for parameter passing. the memory reference where the variable values are stored is copied. The scope of an object is the (A) (B) (C) (D) size of the memory allocated for an object. total number of data attributes used by an object. } Why is this implementation of the Linear Search algorithm is considered undesirable? .78. Both A and B 81.s2). Which of the following declarations is correct? I. (A) (B) (C) (D) String s1 = "Mambo". Consider the linearSearch method below. What information will be stored in string3 as a result of the statement below? String string3 = "100" + "200". III. concat(s1. I only I and II only II and III only I. s2 = "Mambo".length. (A) (B) (C) (D) The String value "100200" The int value 100200 The int value 300 The String value "300" 80. Assume that s1. II. II and III 79. return found. k++) if (intArray[k] == searchNumber) found = true. k < intArray. String s2. Which statement(s) demonstrate(s) string concatenation? (A) (B) (C) (D) s1 = s2. s3 = s1 + s2. public boolean linearSearch(int searchNumber) { boolean found = false.concat("Hello"). String s3 = new String("Mambo"). s2 and s3 are String objects. for (int k = 0. length-p.(A) Searching will continue after a match for searchNumber is found. Consider method whatSort below. q++) if ( intArray[q] > intArray[q+1]) { int temp = intArray[q]. intArray[q] = intArray[q+1]. q < intArray. q++) if ( intArray[q] > intArray[q+1]) { int temp = intArray[q]. intArray[q+1] = temp. The largest integer will be stored in the last array element. Consider method whatSort below. (D) It will return the wrong result if the searchNumber is not found. } } Assume that intArray stores a random list of integers prior to calling whatSort. How will the Integers be arranged after a call to whatSort? (A) (B) (C) (D) 83.length-1. public void whatSort() { for (int q = 0. (C) It will only return the correct result if the first array element is the searchNumber. The smallest integer will be stored in the first array element. public void whatSort() { for (int p = 1. intArray[q] = intArray[q+1].length. Data will be arranged in ascending order. Data will be arranged in descending order. p < intArray. intArray[q+1] = temp. q < intArray. 82. (B) It will only return the correct result if the last array element is the searchNumber. } } Assume that intArray stores a random list of integers prior to calling whatSort. p++) for (int q = 0. How will the Integers be arranged after a call to whatSort? . (B) inserts number into the array. it depends on how whichOne is called. } Method whichOne (A) deletes number from the array. } Method whichOne (A) deletes number from the array. size--. k++) intArray[k] = intArray[k+1]. it depends on the value of index. Assume that index represents the array location where a new array elements needs to be deleted or an existing array element needs to be deleted. Consider method whichOne below. public void whichOne(int index. it depends on how method whichOne is called. (C) either deletes number or inserts number. 85. int number) { for (int k = index. (D) either deletes number or inserts number. Consider method whichOne below. . k < size-1. public void whichOne(int index. (C) either deletes number or inserts number. int number) { for (int k = size-1. k--) intArray[k] = intArray[k-1]. Data will be arranged in descending order. The largest integer will be stored in last array element. k > index.(A) (B) (C) (D) 84. Assume that index represents the array location where a new array elements needs to be deleted or an existing array element needs to be deleted. Variable size represents the number of elements in intArray. The smallest integer will be stored in the first array element. intArray[index] = number. Data will be arranged in ascending order. (B) inserts number into the array. Variable size represents the number of elements in intArray. which swaps the array elements of intArray according to the provided index parameters. The smallest integer will be stored in the first array element. Data will be arranged in descending order. which swaps the array elements of intArray according to the provided index parameters.length. The Bubble Sort is always faster than the Selection Sort. Consider method selectionSort below. if (intArray[p] != intArray[temp]) swap(p. public void selectionSort() { for (int p = 0. Assume that method swap exists. p++) { int temp = p. } } Assume that intArray stores a random list of integers prior to calling selectionSort. q < intArray. q < intArray. p < intArray.length.length-1. q++) . p++) { int temp = p. for (int q = p+1. it depends on the value of index. (D) The Selection Sort is always faster than the Bubble Sort. for (int q = p+1. Consider method selectionSort below.length-1. How does the Selection Sort compare to the Bubble Sort in execution efficiency? (A) (B) (C) data. public void selectionSort() { for (int p = 0.temp). The Selection Sort is usually faster than the Bubble Sort with random The Selection Sort is only faster than the Bubble Sort with sorted data. The largest integer will be stored in last array element. either deletes number or inserts number. 88. p < intArray.(D) 86. How will the Integers be arranged after a call to selectionSort? (A) (B) (C) (D) Data will be arranged in ascending order. 87. Assume that method swap exists. q++) if (intArray[q] < intArray[temp]) temp = q. 180. unlike the Linear Search. because the Binary Search can search any type of data. just like the Smart Bubble Sort. the Smart Selection Sort stops. (D) If the data is sorted already. {100.if (intArray[q] > intArray[temp]) temp = q. 140. 190. (C) The Selection Sort continues to make comparisons until every comparison pass is finished. because the Linear Search is faster than the Binary Search with sorted data. The largest integer will be stored in last array element. How does the Selection Sort behave after all the data is sorted in an array? (A) It stops making comparisons. (C) No. The smallest integer will be stored in the first array element. 120. Assume that intArray contains the following set of sorted integers. 91. 150. 160. the Selection Sort never starts. How will the Integers be arranged after a call to selectionSort? (A) (B) (C) (D) 89. (B) Yes. because the Binary Search is always faster than the Linear Search. Data will be arranged in ascending order.temp). (D) No. } } Assume that intArray stores a random list of integers prior to calling selectionSort. 110. Is the Binary Search always preferred over the Linear Search. otherwise it executes every loop. 170. 130. 90. if (intArray[p] != intArray[temp]) swap(p. (B) The Regular Selection Sort continues sorting. because the Binary Search only works with sorted data. and why? (A) Yes. 200} How many comparisons are made by a Binary Search method to find number 130? (A) (B) (C) (D) 2 3 4 5 . Data will be arranged in descending order. {11.55.66.92.out.88. even if interrupted by another recursive call.77. Public static void count(int a. Consider the count method below. } } What will be displayed by the method call count(10.44. (D) All of the above 94. Which of the following statements is a/are fundamental recursion concept(s)? (A) All recursive methods require an exit or base case.33. Assume that intArray contains the following set of sorted integers. Count(a+1. (B) Every method call will be completed.print(a + " ").20)? (A) (B) (C) (D) 10 11 20 20 11 12 19 19 12 13 18 18 13 14 17 17 14 15 16 16 15 16 15 15 16 17 14 14 17 18 13 13 18 19 12 12 19 20 20 11 10 11 95.22. Consider the count method below. (C) Incomplete recursive calls are executed in a LIFO sequence. int b) { if (a <= b) { . int b) { if (a <= b) { System.99} How many comparisons are made by a Binary Search method to determine that number 50 is not in the list? (A) (B) (C) (D) 2 3 4 5 93. Public static void count(int a. b). count(a+1. 10 11 20 20 11 12 19 19 12 13 18 18 13 14 17 17 14 15 16 16 15 16 15 15 16 17 14 14 17 18 13 13 18 19 12 12 19 20 20 11 10 11 What value will be returned by the call m09(5) ? public static int m09 (int n) { if (n == 1) return 25.20)? (A) (B) (C) (D) 96. What value will be returned by the call m11(1) ? public static int m11(int n) { . What value will be returned by the call m10(5) ? public static int m10 (int n) { if (n == 1) return 25. } (A) (B) (C) (D) 1 5 25 125 97. System.print(a + " "). } (A) (B) (C) (D) 5 39 125 195 98. } } What will be displayed by the method call count(10.out. b). else return n + m10(n-1). else return m09(n-1). b). else return n * m13(n-1). int b) { if (a == 0) return 0. else return b + m14(a-1. } (A) (B) (C) (D) 5 20 24 120 100.6)? public static int m14 (int a. else return n + m11(n+1). } (A) (B) (C) (D) 1 11 30 120 .if (n == 5) return 0. } (A) (B) (C) (D) 99. 1 10 50 75 What value will be returned by the call m13(5) ? public static int m13 (int n) { if (n == 1) return 1. What value will be returned by the call m14(5.
Copyright © 2024 DOKUMEN.SITE Inc.