Unit 4 Exam
What value is returned as a result of the method call changeStr("12345") ?
"53"
What is printed as a result of executing the code segment?
4752
String str = "a black cat sat on a table"; What is printed as a result of executing this code segment?
5
int outerMax = 10; How many values will be printed when the code segment is executed?
60
What value is returned as a result of the call mystery (6)?
8
Which of the following should be used to replace /* missing loop header */ so that the code segment will print 6 as the value of count?
for (int y = 0; y < x; y++)
How many times is the string "Surprise" printed as a result of executing the code segment?
18
Which of the following best explains the effect of simultaneously changing x <= 4 to x < 4 in line 1 and y < 4 to y <= 4 in line 3 ?
"a" will be printed the same number of times because while the number of output lines will decrease by 1, the length of each line will increase by 1.
What is returned as a result of the call mystery("computer") ?
"optr"
int count = 0; for (int x = 0; x < 4; x++) { for (int y = x; y < 4; y++) { count++; } } System.out.println(count); What is printed as a result of executing the code segment
10
Code segment 1 prints the sum of the integers from 1 through 30, inclusive. Which of the following best explains how the output changes from code segment 1 to code segment 2 ?
Code segment 2 will print the sum of only the odd integers from 1 through 30, inclusive because it starts k at one, increments k by twos, and terminates when k exceeds 30.
for (int k = 1; k <= 100; k++) Which of the following code segments will produce the same output as the code segment above?
for (int k = 4; k <= 100; k = k + 4) System.out.println(k);
Which of the following can be used to replace /* missing loop header */ so that the code segment works as intended? for (int j = 0; j < 3; j++) for (int j = 1; j < 3; j++) for (int j = 1; j <= 3; j++)
I and III
The following conditions have been proposed to replace /* condition */ in the code segment. x < 0 x <= 1 x < 10 For which of the conditions will nothing be printed?
I, II, and III
Which of the following best explains how changing the outer for loop header to for (int j = 0; j <= 3; j++) affects the output of the code segment?
The string "Fun" will be printed more times because the outer loop will execute more times.
Which of the following best explains the effect, if any, of changing the first line of code to int j = 0; ?
There will be four more values printed because the outer loop will iterate one additional time.
Which of the following can be used as a replacement for /* missing loop header */ so that the code segment produces the output 00_01_02_11_12_22_ ?
int inner = outer; inner < 3; inner++
Which of the following represents the value returned as a result of the call compute (n, k)
n^k
public int numDigits(int num) Which of the following can be used to replace /* missing condition */ so that the method will work as intended?
num != 0
int r = 0; Which of the following could replace /* missing loop header */ to ensure that the code segment will work as intended?
while (r <= 101)