• ¿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 3 fuera de 21 páginas
Examen

Java - Chapter 5 Quiz – Questions and Answers| Latest Update

Document preview thumbnail
Vista previa 3 fuera de 21 páginas

Java - Chapter 5 Quiz – Questions and Answers| Latest Update

Vista previa del contenido

Java - Chapter 5 Quiz – Questions and
Answers| Latest Update
Suppose the input for number is 9. What is the output from running the following program?


import java.util.Scanner;


public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();


int i;


boolean isPrime = true;
for (i = 2; i < number && isPrime; i++) {
if (number % i == 0) {
isPrime = false;
}
}


System.out.println("i is " + i);


if (isPrime)
System.out.println(number + " is prime");
else

,System.out.println(number + " is not prime");
}
}
A. i is 3 followed by 9 is prime
B. i is 3 followed by 9 is not prime
C. i is 4 followed by 9 is prime

D. i is 4 followed by 9 is not prime ✔️✔️D


Analyze the following code:


import java.util.Scanner;


public class Test {
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i < 100000; i++) {
Scanner input = new Scanner(System.in);
sum += input.nextInt();
}
}
}
A. The program does not compile because the Scanner input = new Scanner(System.in);
statement is inside the loop.
B. The program compiles, but does not run because the Scanner input = new
Scanner(System.in); statement is inside the loop.
C. The program compiles and runs, but it is not efficient and unnecessary to execute the
Scanner input = new Scanner(System.in); statement inside the loop. You should move the
statement before the loop.

, D. The program compiles, but does not run because there is not prompting message for
entering the input ✔️✔️C


What is the output of the following code?


int x = 0;
while (x < 4) {
x = x + 1;
}
System.out.println("x is " + x);
A. x is 0
B. x is 1
C. x is 2
D. x is 3

E. x is 4 ✔️✔️E


What will be displayed when the following code is executed?


int number = 6;
while (number > 0) {
number -= 3;
System.out.print(number + " ");
}
A. 6 3 0
B. 6 3
C. 3 0
D. 3 0 -3

Información del documento

Subido en
21 de marzo de 2025
Número de páginas
21
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$12.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.
KateJones
4.8
(12)
Vendido
32
Seguidores
0
Artículos
5716
Última venta
1 mes 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