What is the value of balance after the following code is executed?
int balance = 10;
while (balance >= 1) {
if (balance < 9)
break;
balance = balance - 9;
}
A. -1
B. 0
C. 1
D. 2
c Before the loop, balance is 10 . The loop-continuation-condition is true (10 >= 1). In the first iteration, balance is reduced to 1 . Since 1 >= 1 is true, the loop body is executed. Since balance < 9 is true, the break statement is executed to exit the loop. So, balance is 1 after the loop is finished. The correct answer for this question is C.
You might also like to view...
The print function outputs a newline by default before its arguments are printed.
Answer the following statement true (T) or false (F)
The ____ responds to keyboard events.
A. KeyListener B. ActionListener C. ChangeListener D. FocusListener
When you draw a shape in a document, word initially places the shape in back of any text in the same area. _________________________
Answer the following statement true (T) or false (F)
When you write custom exceptions, instead of the CLR raising the exception, you must write program statements that raise the exception, using the keyword ____________.
Fill in the blank(s) with the appropriate word(s).