COP2250 JAVA M3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

int x=1; while(x <= 5) { x++; System.out.print(x); } What is output by the code above?

23456

for(int i = 0; i < 6; i++) { for(int j = 1; j <= 5; j++) { System.out.print(i + j + " "); } System.out.println(); } What is printed by the third iteration of the outer loop?

3 4 5 6 7

int n; for(n = 8; n < 30; n += 5) { // } System.out.print(n); What is printed when the loop above has finished?

33

23456

42

In which instance can a loop not require braces?

when only one statement is to be repeated

Identify the true statements regarding Java loops. Select ALL that apply. Question 1 options: For loops are more susceptible to endless loop coding errors than while loops. A do-while loop always runs at least once. While loops are best when the number of loop iterations can be predetermined. A while loop might not run at all. Loops can be nested in other loops to any depth as desired.

A do-while loop always runs at least once. A while loop might not run at all. Loops can be nested in other loops to any depth as desired.

int b =0, sum =0; while (b < 6) { ++b; if(b % 2 == 0) continue; b++; sum = sum + b; } System.out.print(sum); When the above program is run, the output would be 13?

False

4. for(int n = 0; n <= 12; n++) { 5. System.out.print(n + " "); 6. } 7. System.out.println(n); What is the output of line 7?

Nothing. Compilation fails

A while loop is a __?__ loop.

pretest

The Java continue statement causes execution to skip to

the next iteration in the loop


Ensembles d'études connexes

biology 103 final exam review-pearson questions (9)

View Set

Modeling with Systems of Linear Equations: Quiz

View Set

Government: Lesson 5 The U.S. in a Global Economy

View Set