QUIZ 7 COP2258

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the output of the following Java code? int num = 15; while (num > 0) num = num - 3; System.out.println(num);

0

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

1 3 5 7 9

What is the output of the following code? int count; int num = 2; for (count = 1; count < 2; count++) { num = num + 3; System.out.print(num + " "); } System.out.println();

5

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

8

Which of the following loops prints "Welcome to Java" 10 times? A: for (int count = 1; count <= 10; count++) { System.out.println("Welcome to Java"); } B: for (int count = 0; count < 10; count++) { System.out.println("Welcome to Java"); } C: for (int count = 1; count < 10; count++) { System.out.println("Welcome to Java"); } D: for (int count = 0; count <= 10; count++) { System.out.println("Welcome to Java"); }

AB

Which of the following is true about a while loop?

The body of the loop may not execute at all.

The following for loop executes 21 times. (Assume all variables are properly declared.) for (i = 1; i <= 20; i = i + 1) System.out.println(i);

false

The output of the Java code, assuming that all variables are properly declared, is 32. num = 10; while (num <= 32) num = num + 5; System.out.println(num);

false

The output of the Java code, assuming that all variables are properly declared, is: 2 3 4 5 6. n = 2; while (n >= 6) { System.out.print(n + " "); n++; } System.out.println();

false

When nesting loops, the variable in the outer loop changes more frequently. **SPECIAL NOTE: The answer to this question is FALSE!!!! This question has been updated since it's original posting to reflect the correct answer. Everyone will receive full credit for this question!!!

false

Will the following program terminate? int balance = 10; while (true) { if (balance < 9) continue; balance = balance - 9; }

false

Which is an infinite loop?

loopCount = 1; while(loopCount < 3); { System.out.println("Hello"); }

In the case of an infinite while loop, the while expression (that is, the loop condition) is always true.

true

The output of the following Java code is: Stoor. int count = 5; System.out.print("Sto"); do { System.out.print('o'); count--; } while (count >= 5); System.out.println('r');

true


Set pelajaran terkait

Foundations in Personal Finance: Chapter 5 - Life After High School

View Set

Bacteriophages, Influenza, and Viral Study (PPT 3)

View Set

BAS 282: Digital Marketing: SmartBook

View Set