Given array scorePerQuiz has 10 elements. Which assigns element 7 with the value 8?
Question options:
scorePerQuiz = 8;
scorePerQuiz[0] = 8;
scorePerQuiz[7] = 8;
scorePerQuiz[8] = 7;
scorePerQuiz[7] = 8;
What is the index of the last element?int[] numList = new int[50];
Question options:
0
49
50
Unknown, because the array has not been initialized.
49
What is the ending value of the element at index 0?
int[] numbers = new int[10];
numbers[0] = 35;
numbers[1] = 37;
numbers[1] = numbers[0] + 4;
Question options:
0
35
37
39
35
What is the ending value of the element at index 1?
int[] numbers = new int[10];
numbers[0] = 35;
numbers[1] = 37;
numbers[1] = numbers[0] + 4;
Question options:
0
35
37
39
39
How many elements does the array declaration create?
int[] scores = new int[10];
scores[0] = 25;
scores[1] = 22;
scores[2] = 18;
scores[3] = 28;
Question options:
0
4
9
10
10
Which is an invalid access for the array?
int[] numsList = new int[5];
int x = 3;
Question options:
numsList[x-3]
numsList[0]
numsList[x+2]
numsList[(2*x) - x]
numsList[x+2]
Which XXX / YYY declare an array having MAX_SIZE elements and initializes all elements with -1?
final int MAX_SIZE = 4;
int[] myNumbers = new int[XXX];
int i;
for (i = 0; i < YYY; ++i) {
myNumbers[i] = -1;
}
Question options:
MAX_SIZE / MAX_SIZE
MAX_SIZE / MAX_SIZE - 1
MAX_SIZE - 1 / MAX_SIZE
MAX_SIZE - 1 / MAX_SIZE - 1
MAX_SIZE / MAX_SIZE
Which assigns the array's first element with 99?int[] myVector = new int[4];
Question options:
myVector[] = 99;
myVector[-1] = 99;
myVector[0] = 99;
myVector[1] = 99;
myVector[0] = 99;
Which assigns the array's last element with 99?int[] myVector = new int[15];
Question options:
myVector[0] = 99;
myVector[14] = 99;
myVector[15] = 99;
myVector[16] = 99;
myVector[14] = 99;
What are the ending contents of the array? Choices show elements in index order 0, 1, 2.
int[] yearsList = new int[3];
yearsList[0] = 5;
yearsList[1] = yearsList[0];
yearsList[0] = 10;
yearsList[2] = yearsList[1];
Question options:
5, 5, 5
5, 10, 10
10, 10, 10
10, 5, 5
10, 5, 5
Which XXX and YYY correctly output the smallest values? Array userVals contains 100 elements that are integers (which may be positive or negative). Choices are in the form XXX / YYY.
// Determine smallest (min) value
int minVal;
XXX
for (i = 0; i < 100; ++i) {
if (YYY) {
minVal = userVals[i];
}
}
System.out.println("Min: " + minVal);
Question options:
minVal = 0; / userVal > minVal
minVal = 0; / userVal < minVal
minVal = userVals[0]; / userVals[i] > minVal
minVal = userVals[0]; / userVals[i] < minVal
minVal = userVals[0]; / userVals[i] < minVal
The following program generates an error. Why?final int NUM_ELEMENTS = 5;
int[] userVals = new int[NUM_ELEMENTS];
int i;
userVals[0] = 1;
userVals[1] = 7;
userVals[2] = 4;
for (i = 0; i <= userVals.length; ++i) {
System.out.println(userVals[i]);
}
Question options:
Variable i is never initialized.
The array userVals has 5 elements, but only 3 have values assigned.
The integer NUM_ELEMENTS is declared as a constant
The for loop tries to access an index that is out of the array's valid range.
The for loop tries to access an index that is out of the array's valid range.
The numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to?
int[] userVals = new int[20];
int i;
numNegatives = XXX;
for (i = 0; i < 20; ++i) {
if (userValues[i] < 0) {
numNegatives = numNegatives + 1;
}
}
Question options:
No initialization needed
0
-1
userVals[0]
0
Which best describes what is output? Assume v is a large array of ints.
int i;
int s;
s = v[0];
for (i = 0; i < N_SIZE; ++i) {
if (s > v[i]) {
s = v[i];
}
}
System.out.println(s);
Question options:
first value in v
max value in v
min value in v
last value in v
min value in v
Given two arrays, studentNames that maintains a list of student names, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX / YYY.
String[] studentNames = new String[NUM_STUDENTS];
int[] studentScores = new int[NUM_STUDENTS];
int i;
for (i = 0; i < NUM_STUDENTS; ++i) {
if (XXX > 80) {
System.out.print(YYY + " ");
}
}
Question
options:studentNames[i] / studentNames[i]
studentNames[i] / studentScores[i]
studentScores[i] / studentNames[i]
studentScores[i] / studentScores[i]
studentScores[i] / studentNames[i]
Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true?
Question options:
Using two arrays saves memory versus using one array.
Both arrays should be of the same data type.
Both arrays should be declared to have the same number of elements.
The item names should appear in both arrays.
Both arrays should be declared to have the same number of elements.
Given two arrays, which code will output all the arrays' elements, in the order key, item followed by a newline?
Which if branch executes when an account lacks funds and has not been used recently? hasFunds and recentlyUsed are booleans and have their intuitive meanings.
if (!hasFunds && !recentlyUsed)
if (!hasFunds && recentlyUsed)
if (hasFunds && recentlyUsed)
if (hasFunds && !recentlyUsed)
if (!hasFunds && !recentlyUsed)
What values for x cause Branch 1 to execute?
If x > 100 : Branch 1
Else If x > 200: Branch 2
100 to 200
101 or larger
100 or larger
101 to 200
101 or larger
Which is an example of a process?
x + y
int
y, 10
15
x + y
Which XXX will output only values up to 3? i is an int.
for (i = 1; i < 10; i++) { System.out.print(i + " "); XXX { break; } }
if (i != 3)
if (i != 4)
if (i == 4)
if (i == 3)
if (i == 3)
What is the output if count is 4?
for (i = count; i > 0; --i) { // Output i }
4
43210
4321
321
4321
Which for loop will iterate 100 times?
for (i = 0; i < 100; i++)
for (i = 1; i < 99; i++)
for (i = 1; i < 100; i++)
for (i = 0; i < 99; i++)
for (i = 0; i < 100; i++)
The program should output even values between -10 and 10 (inclusive), so -10 -8 ... 8 10. What should XXX be?
for (XXX) { System.out.print(i + " "); }
i = -10; (i * 2) <= 10, ++i
i = -10; (i * 2) < 10; ++i
i = -10; i <= 10; i = i + 2
i = -10; i < 10; i = i + 2
i = -10; i <= 10; i = i + 2
What is not a key advantage of using an enum as below have versus using a string for myCar and string literals like "red", "green", and "black"?
public enum CarColor {RED, GREEN, BLACK} CarColor myCar; myCar = CarColor.GREEN; if (myCar == CarColor.GREEN) { System.out.print("Green is our most popular color"); }
The possible colors are made explicit
The compiler will yield an error for a misspelled color like GREN
Capital letters can be used to make the colors clearer
The compiler will yield an error for an unsupported color like BLUE
Capital letters can be used to make the colors clearer
Which statement is true?
Javadoc tags should precede methods and class definitions
Javadoc comments are intended for the initial developer rather than future programmers who will interface with the code
Javadoc comments are placed in separate files from source code
The @loop tag should be used when appropriate
Javadoc tags should precede methods and class definitions
Which is not a good use of a perfect size array?
university student IDs
names of the week
names of the months
names of marker colors in a box of 8
university student IDs
The world population is over 7 billion. Which declaration uses the fewest bits while guaranteeing that worldPopulation can be assigned the value 7 billion without error?
int worldPopulation;
byte worldPopulation;
short worldPopulation;
long worldPopulation;
long worldPopulation;
Which XXX completes the following code?
import java.util.Scanner; public class GuessMyAge { public static void myGuess(int low, int high, Scanner scnr) { int mid; char userAnswer; mid = (low + high) / 2; System.out.print("Is it " + mid + "? (/=): "); userAnswer = scnr.next().charAt(0); if ((userAnswer != '<') && (userAnswer != '>')) { System.out.println("Great!"); } else { if (userAnswer == '>') { XXX } else { myGuess(low, mid, scnr); } } } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); myGuess(0, 100, scnr); } }