CSC200 #1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

boolean values can be displayed as the words true and false with the ________ format specifier.

%b

Which of the following is not a type of repetition statement in Java? A) do...while statement B) loop statement C) while statement D) for statement

B) loop statement

if (gender == 1){ if (age >= 65) ++seniorFemales; }

if ( gender == 1 && age >= 65 ) ++seniorFemales;

Which expression is equivalent to if (!(grade == sentinelValue))?

if (grade != sentinelValue)

The control variable of a counter-controlled loop should be declared as ________ to prevent errors.

int

Which formatting flag indicates that the floating-point values should be output with a thousands separator?

Comma (,)

Counter-controlled repetition requires ________. A) a control variable and initial value B) a control variable increment (or decrement) C) a condition that tests for the final value of the control variable D) All of these.

D) All of these.

Which of the following statements about the continue statement is true? A) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement. B) The continue statement is used to exit a repetition structure early and continue execution after the loop. C) The continue statement does not alter the flow of control. D) The continue statement is used to continue after a switch statement.

A) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement.

switch(q){ case 1: System.out.println("apple"); break; case 2: System.out.println("orange"); break; case 3: System.out.println("banana"); break; case 4: System.out.println("pear"); case 5: System.out.println("grapes"); default: System.out.println("kiwi"); } Which of the following values for q will result in kiwi being included in the output? A) 3 B) Any integer less than 1 and greater than or equal to 4. C) 2 D) 1

B) Any integer less than 1 and greater than or equal to 4.

segment 1: int i = 0; while (i < 20){ i++; } System.out.println(i); } segment 2: for { int i = 0; i <= 20; i++){ System.out.println(i); Which of the following statements are true? A) The output from these segments is not the same. B) The scope of the control variable i is different for the two segments. C) Both The output from these segments is not the same and The scope of the control variable i is different for the two segments are true. D) Neither The output from these segments is not the same nor The scope of the control variable i is different for the two segments is true.

C) Both The output from these segments is not the same and The scope of the control variable i is different for the two segments are true.

Which of the following statements about a do...while repetition statement is true? A) The body of a do...while loop is executed only if the terminating condition is true. B) The body of a do...while loop is executed only once. C) The body of a do...while loop is always executed at least once. D) None of these.

C) The body of a do...while loop is always executed at least once.

Which of the following code is equivalent to this code segment? int total = 0; for (int i = 0; i <= 20; i += 2) total += i; ---------------------------- A) int total = 0; for (int i = 0, i <= 20, total += i; i += 2); B) int total = 0; for (int i = 20; i < 0; i += 1) total += i; C) int total = 0; for (int i = 0; i <= 20; total += i, i += 2); D) int total = 0; for (int i = 2; i < 20; total += i, i += 2);

C) int total = 0; for (int i = 0; i <= 20; total += i, i += 2);

Which of the following statements about the break statement is false? A) Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch. B) The break statement is used to exit a repetition structure early and continue execution after the loop. C) The break statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. D) A break statement can only break out of an immediately enclosing while, for, do...while or switch statement.

D) A break statement can only break out of an immediately enclosing while, for, do...while or switch statement.

Which statement prints the floating-point value 123.456 right justified with a field width of 10?

System.out.printf("%10.3f", 123.456);

To exit out of a loop completely, and resume the flow of control at the next statement after the loop, use a ________.

break statement


Kaugnay na mga set ng pag-aaral

13 - Lingua Latina - Familia Romana - Capitulum XIII

View Set

Andy Jia's Cisco Final Exam Practice Set

View Set

Care of Chronic Conditions- Safety

View Set

KNES 301 Chapter 6, KNES 301 Midterm

View Set

Understand the principles of infection control ch. 15:1

View Set

Notgrass History Unit 9 Lesson 45

View Set

English Composition I - Quiz 1:Recognizing and Avoiding Plagiarism

View Set

Chapter 13 Capital Budgeting: Estimating Cash Flows and Analyzing Risk (Intermediate Financial Management)

View Set

Как пригласить на встречу? / Meeting invitations

View Set

Introduction to Individuals with Exceptionalities

View Set

SPAVH: Abriendo Paso - Cajas de cartón

View Set