Multiple choice

What is the output of the given program?

public class ScopeTest
{
public static void main (String [] args)
{
int ii = 2;
do
{
System.out.println (ii);
}
while (--ii);
}
}

  1. 1

  2. 2

  3. Null

  4. Infinite loop

  5. Compilation Error

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct choice because the line while (--ii); will cause the compilation to fail. --ii is not a boolean value. A correct line would be while (--ii>0); we can pass only Boolean values to the while loop. So, this is the correct choice.