Home / Java Programming / Flow Control :: Discussion

Discussion :: Flow Control

  1. What will be the output of the program?

      int i = 0;
      while(1

      {
      if(i == 4)
      {
            break;
      }
      ++i;

    }

    System.out.println("i = " + i);

  2. A.

    i = 0

    B.

    i = 3

    C.

    i = 4

    D.

    Compilation fails.

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    Compilation fails because the argument of the while loop, the condition, must be of primitive type boolean. In Java, 1 does not represent the true state of a boolean, rather it is seen as an integer.


Be The First To Comment