nerdexam
Oracle

1Z0-803 · Question #129

Given: public class DoWhile1 { public static void main (String[] args) { int i = 2; do { System.out.println(i); } while (--i); } } What is the result?

The correct answer is E. Compilation fails. Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from int to boolean

Using Loop Constructs

Question

Given:

public class DoWhile1 { public static void main (String[] args) { int i = 2; do { System.out.println(i); } while (--i); } } What is the result?

Options

  • A2
  • B2
  • CAn exception is thrown at runtime
  • DThe loop executes infinite times
  • ECompilation fails

How the community answered

(47 responses)
  • A
    2% (1)
  • B
    6% (3)
  • C
    4% (2)
  • E
    87% (41)

Explanation

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from int to boolean

Topics

#do-while loop#implicit type conversion#boolean expressions#compilation errors

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice