Output of Code
Strings
Arrays
Boolean Expressions
if statements/for loops
100

What is output?

int x = 9;
System.out.println(x / 2);

4

100

Which of the following is NOT a primitive data type?

String

100

The following is intended to count the number of times the number 87 is found in an array of test scores:

int [] d = / Assume array is initialized /;
int scoreCount = 0;
for (int i = 0; i < d.length; i++) {
if (/ Missing Code /)
scoreCount++;
}
System.out.println("Number of 87's: " + scoreCount);
Which of the following could replace / Missing Code / so that the code works as intended?

d[i] == 87

100

The following truth table matches which boolean condition?
A B ________
1 1 1
1 0 1
0 1 0
0 0 1

A || (!A && !B)

100

What are if statements used for in programs?

Making decisions

200

What is output?
System.out.println("The answer is: " + 5 + 19);

The answer is: 519

200

What's the largest data type?

String

200

Consider the following code, intended to count the number of words in the array with a length less than or equal to 6.

String vocabulary [] = / Array initialized with Strings /;
int c = 0;
for (int i = 0; i < vocabulary.length; i++) {
if ( / Missing Code /)
c++;
}
System.out.println("Number of words with length less than or equal to 6: " + c);

What could be used to replace / Missing Code / so that the code works as intended?

vocabulary[i].length() <= 6

The following is intended to count the number of times the number 87 is found in an array of test scores:

200

Consider the following boolean statement:

!( x >= y || w == z )

Which of the following will produce the same result?

x >= y || w != z

200

Which if statement below tests if letter holds R? (letter is a char variable)

if (letter == 'R')

300

Consider the following code:

double x = -97.6;
System.out.println(Math.abs(x));

What is output?

97.6

300

What does the String method charAt() do?

Returns the character at a certain location in the String object.

300

What does the following method do?

public static int mystery(int a[], int x) {
int c = 0;
for(int i = 0; i < a.length; i++) {
if (a[i] == x)
c++;
}
return c;
}

Returns a count of the number of times x appears in the array.

300

Assume that x and y are boolean variables and have been properly initialized.

!(x || y) || (x || y)

The result of evaluating the expression above is best described as:

always true

300

What are for loops in java?

controlled loop that allows a user to execute a block of a statements

400

What is output to the screen by the following code?

int num = 1987;
while (num > 0) {
num = num / 10;
System.out.print(num % 10 + " ");
}

8 9 1 0

400

What does the following code do?

String w3 = "aardvark";
System.out.println(w3.charAt(w3.length()-2));

Prints the second to last letter in the String.

400

What does the following algorithm do?

public static boolean mystery(int nums[]) {
for (int i = 1; i < nums.length; i++)
if (nums[i - 1] >= nums[i])
return false;
return true;
}

Returns true if each element of the array is greater than the element before.

400

Consider the code:

if ( y == 0 || x * y > 10)

Which of the following is an example of short circuit evaluation?

if y == 0 is true it doesn't evaluate x * y > 10

400

Consider the following code:

int [] a = {2, 6, 8, 10, 12, 14, 16, 18};
int sum = 0;
for(int i = 0; i < a.length; i++) {
if ( i%3 == 0 )
sum += a[i];
}
System.out.println(sum);

What is output?

28

500

What is output to the screen by the following code?

int c = 2;
while (c < 6) {
System.out.print((int)Math.pow (-1, c)+" ");
c++;
}

1 -1 1 -1

500

Consider the following code:

String w = "Rapunzel";
for (int i = 0; i < w.length(); i++) {
if ( i%4 != 2)
System.out.print(w.charAt(i) + " ");
}
What is output?

R a u n z l

500

What does the following algorithm do?

public static void mystery(int nums[]) {
for (int i = 0; i < nums.length; i++) {
if (nums[i] % 2 != 0)
nums[i]++;
}
}

Changes all the values in the array to even numbers.

500

What are Boolean expressions?

True or false

500

What is output by the following code?

for (int i = 0; i <= 5; i++) {
System.out.print(i + " ");
}

0 1 2 3 4 5

M
e
n
u