Java chapter 4 quiz review

Ace your homework & exams now with Quizwiz!

int count = 0; do { System.out.println("Welcome to Java"); } while (count++ < 10);

11

The following loop displays ________. for (int i = 1; i <= 10; i++) { System.out.print(i + " "); i++; }

1 3 5 7 9

How many times will the following code print "Welcome to Java"? int count = 0; do { System.out.println("Welcome to Java"); } while (++count < 10);

10

What is the value in count after the following loop is executed? int count = 0; do { System.out.println("Welcome to Java"); } while (count++ < 9); System.out.println(count);

10

How many iterations will the following loop execute? for (int i = 0; i < 20; i++) { System.out.println("i = " + i); }

20

How many times is the println statement executed in the following code block? for (int i = 0; i < 10; i++) for (int j = 0; j < i; j++) System.out.println(i * j);

45

How many iterations will the following loop execute? for (int i = 1; i < 20; i *= 2) { System.out.println("i = " + i); }

5

The ________ statement results in a premature exit from a loop.

Break

Analyze the following statement: double sum = 0; for (double d = 0; d < 10; ) { d += 0.1; sum += sum + d; }

NOT The program runs in an infinite loop because d < 10 would always be true.

Which one of the following loops prints "Welcome to Java" 10 times?

Selected Answer: for (int count = 0; count < 10; count++) { System.out.println("Welcome to Java"); }

A ________ is frequently used in a loop when reading input to signify the end of the input.

Sentinel Value

Which one of the following loops is a posttest loop?

The DO-WHILE loop

Which of the following is the correct declaration of a FOR loop which will iterate 5 times, assuming an integer variable named 'i'?

for (i = 0; i < 5; i++) System.out.println("i = " + i);

What is the output after the following loop terminates? int number = 25; int i; boolean isPrime = true; for (i = 2; i < number && isPrime; i++) { if (number % i == 0) { isPrime = false; } } System.out.println("i is " + i + " isPrime is " + isPrime);

i is 6 isPrime is false


Related study sets

Section 2 - Producer responsibilities

View Set

CHAPTER 12 - Aggregate Demand & Aggregate Supply

View Set

CHAPTER 10: GLOBAL WARMING AND OZONE DEPLETION

View Set

Chapter 2 Review Questions - US History

View Set