Java if statement Question 4

Question

What is the output of the following code?


public class Main {
  public static void main(String args[]) {

    int done = 0;

    if (!done) {// w w  w  .  j  av a 2 s. c  om
      System.out.println("Not done");
    }
    if (done) {
      System.out.println("done");
    }
  }
}


Compile time error

Note

In Java the int type cannot be using as a boolean value.

In Java, these statements must be written like this:

if(done == 0)... // This is Java-style.  
if(done != 0)... // This is Java-style.  



PreviousNext

Related