Practice Test 01
What is the largest number of comparisons needed to perform a binary search on an array with 42 elements?
2
5
6
41
42
6
Practice Test 01
Which of the following are valid arrays?
I. int[] coolArray = {1, 2, 3};
II. int[] threeThings = {1.0, 2.0, 3.0};
III. int[] = {“1”, “2”, “3”};
I only
II only
III only
I and II
I and III
I only
Practice Test 01
What is the output of the following program?

Correct! Specifically, the <= in the for loop results in an attempt to access data that is out of the array’s bounds.
Practice Test 01
What values will the array contain after the following the code is run?
int[] someArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
for (int i = someArray.length - 2; i >= 0; i-=2)
{
someArray[i] = someArray[i] - 5;
}
2. {1, -3, 3, -1, 5, 1, 7, 3, 9, 5, 11}
Practice Test 01
What is the proper way to compare String values in Java?
Practice Test 01
What result would be printed given these commands:
SomeFavorites mystery = new SomeFavorites();
mystery. listSomething();
mystery. anotherThing();

42
42
Practice Test 01
What are the values of the variables x, y, and z after this code snippet runs?
int x = 0;
int y = 10;
int z = 20;
x = y;
y = y * 2;
z = 30;
Practice Test 01
Your robot Baymax seems to have a bug in his battery. The problem is Baymax will only stay on if his battery is at 100%. Anything lower than 100% and Baymax shuts off. What is the bug in this code snippet?
Hint : Baymax represents his battery life as a decimal number between 0 and 1.

Practice Test 01
What would be a correct way to instantiate this 2D array?

Practice Test 01
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3},
{6.1, 10.2, 1.3, -2.5},
{1.1, 2.3, 5.8, 13.21, 34.55} }
What is the value of something[1][2]?
The array does not have an element at that location.
1.3
Practice Test 01
What is the proper way to get the number of items in an ArrayList called list?
Practice Test 01
What is the output of the following lines?
Practice Test 01
Which expression is true?
Practice Test 01
What will this program print if the value of grade is 80?

C
Practice Test 01
What will the values of x and y be after this code segment runs?

x = 99
y = 199
Practice Test 01
Refer to the following code segment:
double myDouble = 1/4;
System.out.println(“1 / 4 = “ + myDouble);
The output of the code is:
1 / 4 = 0.0
The student wanted the output to be:
1 / 4 = 0.25
Which change to the first line of their code segment would get the student the answer that they wanted?
2. double myDouble = (double) 1/4;
Practice Test 01
What will the following code print?

Java
Practice Test 01
What is wrong with the following code?
ArrayList list = new ArrayList();
list.add(1);
System.out.println(list.get(0));
Practice Test 01
What does this method call output?
public double doubleNumber(double myNumber)
{
return (double) (int) myNumber * 2;
}
doubleNumber(7.8);
16
This method is improperly written.
Answered
14.0
Practice Test 01
Consider the following code segment:
String str = “I am”;
str += 10 + 3;
String age = “years old”;
System.out.println(str + age);
What is printed as a result of executing the code segment?
Practice Test 01
What would this method call output?

divideByTen(340)
34
Practice Test 01
What is the output of this method call?
public String wordScramble(String myWord)
{
myWord.substring(2) + myWord.charAt(3) + “dot”;
}
wordScramble(“polkadot”)
Practice Test 01
What kind of error does this method cause?
myMethod(“Frog”);

Practice Test 01
What does this method call output?

someMethod(3,1)
10