CSE 110 STUDY GUIDE QUESTIONS
WITH ANSWERS AND EXPLANATIONS
1. What numeric value is assigned to result?
double result = Math.abs(-8);
A. 8
B. 9
C. -8
D. 0
Correct Answer: A. 8
Explanation: Math.abs returns the magnitude of its argument, so a negative value becomes positive.
2. A parking application uses the Java fragment below while working with primitive parameter passing.
What value is printed, and why?
static void change(int value) {
value = value + 10;
}
int n = 11;
change(n);
System.out.println(n);
A. 10, because the argument is replaced by the parameter.
B. 21, because parameters are aliases for all primitive variables.
C. 0, because void methods reset their arguments.
D. 11, because changing the primitive parameter does not change the caller's variable.
Correct Answer: D. 11, because changing the primitive parameter does not change the caller's variable.
Explanation: Java passes primitive argument values by value. The parameter receives a copy, so assigning to the
parameter does not alter the original variable.
3. A shipping calculator needs to store the whether a door is locked. Which type is the most appropriate?
A. String
B. int
C. double
D. boolean
Correct Answer: D. boolean
Explanation: boolean matches the kind of value described. The other choices represent different categories of data or an
unnecessarily restrictive representation.
,4. In a reservation system, the following fragment is used to apply two-dimensional arrays. What value is
stored in count after the nested traversal?
int count = 0;
int[][] grid = new int[4][5];
for (int r = 0; r < grid.length; r++)
for (int c = 0; c < grid[r].length; c++)
count++;
A. 21
B. 9
C. 20
D. 19
Correct Answer: C. 20
Explanation: The inner loop visits every column in each row, so the total number of visits equals rows multiplied by
columns.
5. For scenario Study Guide-89, what does this.width refer to inside the constructor?
class Box {
private int width;
Box(int width) {
this.width = width;
}
}
A. The width field of the current Box object.
B. A static field in the Math class.
C. The width of every object in every class.
D. The local parameter only.
Correct Answer: A. The width field of the current Box object.
Explanation: this refers to the current object. Qualifying the field as this.width distinguishes it from the parameter named
width.
,6. What value is stored in pos after this linear search?
int[] data = {31, 51, 54, 50, 46, 35, 30};
int target = 99;
int pos = -1;
for (int i = 0; i < data.length; i++) {
if (data[i] == target) { pos = i; break; }
}
A. -1
B. 99
C. 7
D. 0
Correct Answer: A. -1
Explanation: The loop scans indexes from left to right and stops at the first match. If no match is found, pos remains at its
sentinel value of -1.
7. For scenario Study Guide-93, which member normally represents behavior that an object can perform?
A. A filename extension
B. An import statement
C. An instance method
D. A primitive literal only
Correct Answer: C. An instance method
Explanation: Methods define behavior. Instance methods operate in the context of a particular object.
8. What is the Boolean value of the expression !(9 >= 7)?
A. 0
B. false
C. 1
D. true
Correct Answer: B. false
Explanation: Relational expressions are evaluated first, then the logical operators combine or negate the resulting Boolean
values according to Java rules.
, 9. What inclusive range can value take?
int value = rng.nextInt(7) + 8;
A. 8 through 14
B. 0 through 6
C. 9 through 15
D. 8 through 15
Correct Answer: A. 8 through 14
Explanation: nextInt(n) produces 0 through n-1. Adding the offset shifts both endpoints upward by that amount.
10. For scenario Study Guide-46, which approach is most appropriate when the number of user inputs is
not known in advance but processing stops on a special value?
A. A constant declaration only
B. A fixed-size arithmetic expression
C. A sentinel-controlled while loop
D. A switch with no loop
Correct Answer: C. A sentinel-controlled while loop
Explanation: A sentinel-controlled loop is designed for input sequences whose length is not known before execution.
11. What is displayed for the current value of x?
int x = 2;
if (x >= 24) {
System.out.println("high");
} else if (x >= 5) {
System.out.println("middle");
} else {
System.out.println("low");
}
A. nothing
B. low
C. high
D. middle
Correct Answer: B. low
Explanation: An if/else-if chain selects the first condition that evaluates to true and skips the remaining alternatives.
WITH ANSWERS AND EXPLANATIONS
1. What numeric value is assigned to result?
double result = Math.abs(-8);
A. 8
B. 9
C. -8
D. 0
Correct Answer: A. 8
Explanation: Math.abs returns the magnitude of its argument, so a negative value becomes positive.
2. A parking application uses the Java fragment below while working with primitive parameter passing.
What value is printed, and why?
static void change(int value) {
value = value + 10;
}
int n = 11;
change(n);
System.out.println(n);
A. 10, because the argument is replaced by the parameter.
B. 21, because parameters are aliases for all primitive variables.
C. 0, because void methods reset their arguments.
D. 11, because changing the primitive parameter does not change the caller's variable.
Correct Answer: D. 11, because changing the primitive parameter does not change the caller's variable.
Explanation: Java passes primitive argument values by value. The parameter receives a copy, so assigning to the
parameter does not alter the original variable.
3. A shipping calculator needs to store the whether a door is locked. Which type is the most appropriate?
A. String
B. int
C. double
D. boolean
Correct Answer: D. boolean
Explanation: boolean matches the kind of value described. The other choices represent different categories of data or an
unnecessarily restrictive representation.
,4. In a reservation system, the following fragment is used to apply two-dimensional arrays. What value is
stored in count after the nested traversal?
int count = 0;
int[][] grid = new int[4][5];
for (int r = 0; r < grid.length; r++)
for (int c = 0; c < grid[r].length; c++)
count++;
A. 21
B. 9
C. 20
D. 19
Correct Answer: C. 20
Explanation: The inner loop visits every column in each row, so the total number of visits equals rows multiplied by
columns.
5. For scenario Study Guide-89, what does this.width refer to inside the constructor?
class Box {
private int width;
Box(int width) {
this.width = width;
}
}
A. The width field of the current Box object.
B. A static field in the Math class.
C. The width of every object in every class.
D. The local parameter only.
Correct Answer: A. The width field of the current Box object.
Explanation: this refers to the current object. Qualifying the field as this.width distinguishes it from the parameter named
width.
,6. What value is stored in pos after this linear search?
int[] data = {31, 51, 54, 50, 46, 35, 30};
int target = 99;
int pos = -1;
for (int i = 0; i < data.length; i++) {
if (data[i] == target) { pos = i; break; }
}
A. -1
B. 99
C. 7
D. 0
Correct Answer: A. -1
Explanation: The loop scans indexes from left to right and stops at the first match. If no match is found, pos remains at its
sentinel value of -1.
7. For scenario Study Guide-93, which member normally represents behavior that an object can perform?
A. A filename extension
B. An import statement
C. An instance method
D. A primitive literal only
Correct Answer: C. An instance method
Explanation: Methods define behavior. Instance methods operate in the context of a particular object.
8. What is the Boolean value of the expression !(9 >= 7)?
A. 0
B. false
C. 1
D. true
Correct Answer: B. false
Explanation: Relational expressions are evaluated first, then the logical operators combine or negate the resulting Boolean
values according to Java rules.
, 9. What inclusive range can value take?
int value = rng.nextInt(7) + 8;
A. 8 through 14
B. 0 through 6
C. 9 through 15
D. 8 through 15
Correct Answer: A. 8 through 14
Explanation: nextInt(n) produces 0 through n-1. Adding the offset shifts both endpoints upward by that amount.
10. For scenario Study Guide-46, which approach is most appropriate when the number of user inputs is
not known in advance but processing stops on a special value?
A. A constant declaration only
B. A fixed-size arithmetic expression
C. A sentinel-controlled while loop
D. A switch with no loop
Correct Answer: C. A sentinel-controlled while loop
Explanation: A sentinel-controlled loop is designed for input sequences whose length is not known before execution.
11. What is displayed for the current value of x?
int x = 2;
if (x >= 24) {
System.out.println("high");
} else if (x >= 5) {
System.out.println("middle");
} else {
System.out.println("low");
}
A. nothing
B. low
C. high
D. middle
Correct Answer: B. low
Explanation: An if/else-if chain selects the first condition that evaluates to true and skips the remaining alternatives.