4.11. Multiple Choice Exercises

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

How many times does the following method print a * ? for (int i = 1; i < 5; i++) { System.out.print("*"); } A. 4 B. 5 C. 6

A

How many times does the following method print a * ? for (int x = 2; x < 8; x++) { System.out.print("*"); } A. 6 B. 7 C. 8

A

Which of the following code segments will produce the displayed output? 1 22 333 4444 55555 I. for (int i = 1; i <= 5; i++) { for (int j = i; j > 0; j--) { System.out.print(i); } System.out.println(); } II. for (int i = 0; i < 5; i++) { for (int j = 0; j < i; j++) { System.out.print(i); } System.out.println(); } III. for (int i = 1; i < 5; i++) { for (int j = i; j > 0; j--) { System.out.print(i); } System.out.println(); } IV. for (int i = 1; i < 6; i++) { for (int j = 0; j < i; j++) { System.out.println(i); } } V. for (int i = 0; i < 5; i++) { for (int j = 0; j < i; j++) { System.out.print(i+1); } System.out.println(); } A. I B. II C. III D. IV E. V

A

Which of the following code segments will produce the displayed output? 11111 2222 333 44 5 I. for (int j = 1; j <= 5; j++) { for (int k = 5; k >= j; k--) { System.out.print(j); } System.out.println(); } II. for (int j = 1; j <= 5; j++) { for (int k = 5; k >= 1; k--) { System.out.print(j); } System.out.println(); } III. for (int j = 1; j <= 5; j++) { for (int k = 1; k <= j; k++) { System.out.print(j); } System.out.println(); } IV. for (int j = 1; j <= 5; j++) { for (int k = 1; k <= 5; k++) { System.out.println(j); } } V. for (int j = 1; j <= 5; j++) { for (int k = j; k <= 5; k++) { System.out.print(k); } System.out.println(); } A. I B. II C. III D. IV E. V

A

How many times does the following method print a * ? for (int i = 5; i <= 12; i++) { System.out.print("*"); } A. 7 B. 8 C. 12 D. 13

B

How many times does the following method print a * ? for (int x = 0; x < 5; x++) { System.out.print("*"); } A. 4 B. 5 C. 6

B

How many stars are output when the following code is executed? for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) System.out.println("*"); } A. 10 B. 5 C. 25 D. 50 E. 15

C

How many times does the following method print a * ? for (int i = 0; i <= 8; i++) { System.out.print("*"); } A. 7 B. 8 C. 9

C

How many times does the following method print a * ? for (int i = 3; i < 9; i++) { System.out.print("*"); } A. 9 B. 7 C. 6 D. 10

C

What does the following code print? int x = -5; while (x < 0) { x++; System.out.print(x + " "); } A. 5 4 3 2 1 B. -5 -4 -3 -2 -1 C. -4 -3 -2 -1 0

C

What are the values of var1 and var2 after the following code segment is executed and the while loop finishes? int var1 = 0; int var2 = 2; while ((var2 != 0) && ((var1 / var2) >= 0)) { var1 = var1 + 1; var2 = var2 - 1; } A. var1 = 0, var2 = 2 B. var1 = 1, var2 = 1 C. var1 = 3, var2 = -1 D. var1 = 2, var2 = 0 E. The loop won't finish executing because of a division by zero.

D

What does the following code print? for (int i = 3; i <= 12; i++) { System.out.print(i + " "); } A. 5 6 7 8 9 B. 4 5 6 7 8 9 10 11 12 C. 3 5 7 9 11 D. 3 4 5 6 7 8 9 10 11 12

D

What does the following code print? int x = 0; while (x <= 5) { System.out.print(x + " "); x++; } A. 1 2 3 4 B. 1 2 3 4 5 C. 0 1 2 3 4 D. 0 1 2 3 4 5

D

What does the following code print? int x = 3; while (x < 9) { System.out.print(x + " "); } A. 3 4 5 6 7 8 B. 3 4 5 6 7 8 9 C. 0 1 2 3 4 5 6 7 8 D. 0 1 2 3 4 5 6 7 8 9 E. It is an infinite loop

E

What is printed as a result of the following code segment? for (int k = 0; k < 20; k+=2) { if (k % 3 == 1) System.out.print(k + " "); } A. 0 2 4 6 8 10 12 14 16 18 B. 4 16 C. 0 6 12 18 D. 1 4 7 10 13 16 19 E. 4 10 16

E


Kaugnay na mga set ng pag-aaral

Simple and Complete Subjects and Predicates Practice

View Set

114 Immunity/Oncology PrepU Quiz

View Set

Pediatric integumentary disorers.

View Set

AP Biology The Molecular Basis of Inheritance Review

View Set

Unit 6 - Sub-Saharan Africa Test Review

View Set

Chapter 14: The Physiology of Digestion

View Set