A primitive data type whose value is true or false.
boolean
True/False
An enhanced for loop can be used to replace each element of an int array with the value 0.
false
If an array, arr, contains 100 int values, what does the following statement do?
int x = arr[100];
Throws an ArrayIndexOutOfBoundsException error
A block of code in a class used to create an object of the class.
Constructor
Write an accessor method for the int variable count.
public int getCount()
An object reference that is uninitialized has this as a default value.
null
If the int variable num is initialized, write a statement that uses a compound assignment operator to store in num the remainder when num is divided by 5.
num %= 5; or num = num % 5;
("cat".substring(-1)).compareTo("caP".substring(1)) < 0
What does the above code result in?
A StringIndexOutOfBoundsException error
The average between best case and worst case run times within an algorithm.
Average case
System.out.print(13 / (2 * 3));
What will this print out?
2
Used in the first line of all class declarations.
class
True/False
If String s = "4"; and if int n = 3; then the statement String s3 = s + n; will assign the String value "43" to s3.
true
if sum is an int variable whose value is 0 and if amount is an int variable with value 100, what will be returned by the following statement?
return sum / amount;
0
What is postcondition and precondition?
Post: A statement of what is true immediately after execution of code.
Pre: A statement of what is true immediately before execution of code.
Suppose theComments is an ArrayList<String> of 9 comments. Write one statement that randomly returns, in a string, one of the comments in theComments list.
String comment = theComments.get((int) (Math.random() * 9));
What is the difference between public and private when used in a variable and method?
Private is usable only in the class declared whilst public is usable in outside classes.
Write a statement that prints the top right-hand corner element of a 5 x 7 matrix of int elements called mat. Your statement should leave the cursor on the same line.
System.out.print(mat[0][6]);
"catastrophe".indexOf("he");
What will be the result of the code above?
9
A superclass/subclass connection between classes.
Inheritance or Inheritance relationship between classes
Suppose an array of int is to be sorted in decreasing order using the selection sort algorithm. If the array originally contains 2 8 10 6 5 13, what will the array look like after 2 passes of the sorting loop?
13 10 8 6 5 2
Explanation: The selection sort finds the largest element in the array, starting at the 1st element and then swaps it with the 1st element. The selection sort begins the process again using the next elements.
extends allows for the _______ to inherit from the ________.
Subclass and Superclass
If s1 is a String containing "fur" and if s2 is a String containing "further", then the expression (s1.compareTo(s2) > 0)) will have value true.
false
Which is more efficient for sorting an array of random integers:
A)Merge Sort
B)Binary Search
C)Selection sort
A)Merge Sort
The termination condition that causes a recursive method to end. Give an example as well as its name.
Base Case
if(n == 1)
return;
An array of cities, where each City object has a name of type String and a population of type int, is sorted in alphabetical order based on names of cities. What is the most efficient searching algorithm that will determine whether a given city is in the array?
Binary Search
Explanation: This type of search uses a "divide and conquer" approach that chops the array in two and then in two again, until just one element remains to be examined, requiting fewer comparisons.