How many times will the following code print "Welcome to Java"?

int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 10);
a. 8
b. 9
c. 10
d. 11
e. 0

d The count is initialized to 0 before the loop. The loop is executed for the first time when count is 0 . (count++ < 10) increments count by 1 and uses the old count value to check if count < 10 . So, the loop is executed 11 times for count from 0 to 10 . Note that when count is 10, the loop body is executed before the loop is exited. The correct answer is D.

Computer Science & Information Technology

You might also like to view...

A preformatted database that contains prebuilt tables, queries, forms, and reports that perform a specific task, such as tracking events

a. Imported database b. Online database c. Database template

Computer Science & Information Technology

Pressing Ctrl while dragging an object or selected text creates a copy of the object or text

Indicate whether the statement is true or false

Computer Science & Information Technology