• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 9 páginas
Examen

CMSC 131 Object Oriented Programming I Unit Test 2 - Questions with Correct Answers (Verified Update)

Document preview thumbnail
Vista previa 2 fuera de 9 páginas

CMSC 131 Object Oriented Programming I Unit Test 2 (University of Maryland): 17 exam questions with verified correct answers and rationales, for CMSC 131 at University of Maryland. 9 pages, 2026 verified update. Sample questions covered: What should a programmer assert to reason about the running total before each pass? | String s = "orbit"; What is the value of ring(2, 4)? | Which method compares text content rather than asking whether two references are identical? | Why might a loop with an initially true test never exit?

Vista previa del contenido

CMSC 131 Object-Oriented Programming I: Unit Test 2
Questions and Answers - University of Maryland

1. What should a programmer assert to reason about the running total before each pass?
A. A bounded quantity changes consistently toward its stopping condition
B. Its state never changes in a way that can end the loop
C. An invariant relating the total to the processed inputs
D. An accumulator
Answer: C. An invariant relating the total to the processed inputs
Rationale: A loop invariant is a property that holds at a specified point on every iteration.


2. String s = "orbit"; What is the value of s.substring(2, 4)?
A. it
B. o
C. bi
D. bit
Answer: C. bi
Rationale: The starting index is included and the ending index is excluded.


3. Which method compares text content rather than asking whether two references are identical?
A. As a local variable inside that method
B. String.equals
C. The method receives a copy of the int argument value
D. Declare the static helper private
Answer: B. String.equals
Rationale: String.equals compares character content when invoked on a nonnull String.

,4. int n = 13; int c = 0; while (n >= 3) { n -= 3; c++; } What is the value of n + ":" + c?
A. 1:4
B. 4:3
C. 1:5
D. 4:1
Answer: A. 1:4
Rationale: The loop subtracts three until n is below three. The two outputs count the leftover and
the number of subtractions.


5. Why might a loop with an initially true test never exit?
A. Loop initialization
B. Inside the outer loop before each row's inner loop starts
C. Use a column loop inside a row loop
D. Its state never changes in a way that can end the loop
Answer: D. Its state never changes in a way that can end the loop
Rationale: An infinite loop continues because no reachable state makes its condition stop and no exit
is taken.


6. A team compares loop initialization with off-by-one error. Which examples fit in the same order?
A. A count starts at zero before any values are read. / The program stops upon reading a specific
value reserved as a terminator.
B. A counter's value is tested against a limit before processing. / A loop intended to repeat five
times repeats six because it uses an inclusive endpoint.
C. A count starts at zero before any values are read. / A loop intended to repeat five times repeats
six because it uses an inclusive endpoint.
D. A loop intended to repeat five times repeats six because it uses an inclusive endpoint. / A count
starts at zero before any values are read.
Answer: C. A count starts at zero before any values are read. / A loop intended to repeat five times
repeats six because it uses an inclusive endpoint.
Rationale: Initialization establishes the starting state before iteration. An off-by-one error includes or
excludes an unintended boundary element.

Información del documento

Subido en
20 de noviembre de 2026
Número de páginas
9
Escrito en
2026/2027
Tipo
Examen
Contiene
Preguntas y respuestas
$8.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
DrJon
3.8
(161)
Vendido
620
Seguidores
188
Artículos
29629
Última venta
2 días hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes