1Z0-803 · Question #234
Given: public class MyClass { public static void main(String[] args) { while (int ii = 0; ii < 2) { ii++; System.out.println("ii = " + ii); } } } What is the result?
The correct answer is B. Compilation fails. The while statement is incorrect. It has the syntax of a for statement. The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: while (expression) { The while statement evaluates expression, which must r
Question
Given:
public class MyClass { public static void main(String[] args) { while (int ii = 0; ii < 2) { ii++; System.out.println("ii = " + ii); } } } What is the result?
Options
- Aii = 1
- BCompilation fails
- CThe program prints nothing
- DThe program goes into an infinite loop with no output
- EThe program goes to an infinite loop outputting:
How the community answered
(61 responses)- B89% (54)
- C7% (4)
- D2% (1)
- E3% (2)
Explanation
The while statement is incorrect. It has the syntax of a for statement. The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: while (expression) { The while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates
Topics
Community Discussion
No community discussion yet for this question.