Term
The code below is an example of a(n) ____ loop.
Scanner cin = new Scanner(System.in);
boolean found = true;
while (found) { int entry = cin.nextInt(); int triple = entry * 3; if (entry > 33) found = false; } Answer A. counter-controlled B. EOF-controlled C. sentinel-controlled D. flag-controlled |
|
Definition
|
|
Term
What is the output of the following Java code?
int count = 1; int num = 25; while (count < 25) { num = num - 1; count++; } System.out.println(count + " " + num); Answer A. 24 0 B. 25 1 C. 25 0 D. 24 1 |
|
Definition
|
|
Term
Suppose the input entered by the user is:
18 25 61 6 -1
What is the output of the following code?
Scanner cin = new Scanner(System.in);
int sum = 0; int num = cin.nextInt(); while (num != -1) { sum = sum + num; num = cin.nextInt(); } System.out.println(sum); Answer A. 92 B. 109 C. 110 D. None of these |
|
Definition
|
|
Term
What is the output of the following Java code?
Which executes immediately after a continue statement in a for loop? Answer A. initial statement B. the body of the loop C. update statement D. loop condition |
|
Definition
|
|
Term
int j; for (j = 10; j <= 10; j++) System.out.print(j + " "); System.out.println(j); Answer A. 10 B. 11 11 C. 10 10 D. 10 11 |
|
Definition
|
|
Term
Which of the following is the update expression in the for loop below?
for (int i = 1; i < 20; i++) System.out.println("Hello World"); System.out.println("!"); Answer A. System.out.println("Hello World"); B. i < 20; C. i++; D. i = 1; |
|
Definition
|
|
Term
Suppose the input entered by the user is:
4 7 12 9 -1
What is the output of the following code?
Scanner cin = new Scanner(System.in); int sum, num, j;
sum = cin.nextInt(); num = cin.nextInt();
for (j = 1; j <= 3; j++) { num = cin.nextInt(); sum = sum + num; } Answer A. 24 B. 42 C. 25 D. 41 |
|
Definition
|
|
Term
Which of the following loops is guaranteed to execute at least once? Answer A. sentinel-controlled while loop B. for loop C. do...while loop D. counter-controlled while loop |
|
Definition
|
|
Term
Which executes first in a do...while loop? Answer A. update expression B. initial statement C. logical expression D. statement |
|
Definition
|
|
Term
Which of the following is NOT a reserved word in Java? Answer A. do B. loop C. while D. for |
|
Definition
|
|
Term
Which of the following does not have an entry condition? Answer A. for loop B. EOF-controlled while loop C. sentinel-controlled while loop D. do...while loop |
|
Definition
|
|
Term
What is the final value of x in the code below? int x = 5; int y = 30;
do x = x * 2; while (x < y); Answer A. 5 B. 10 C. 40 D. 20 |
|
Definition
|
|
Term
What is the output of the following Java code?
int x = 7; boolean found = false;
do { System.out.print(x + " "); if (x <= 2) found = true; else x = x - 5; } while (x > 0 && !found);
System.out.println(); Answer A. 7 B. 2 7 C. 7 2 D. None of these |
|
Definition
|
|