Day 3: Intro to Conditional Statements

  • + 0 comments

    Interesting thing to note:

    In Java this line gives an error while in javascript it will execute:

    (N >= 6 && N <= 20) ? System.out.println("Weird"): System.out.println("Not Weird");

    The Java compiler expects the ternary operator to be used as an expression, not as a statement. When the compiler encounters the System.out.println statements, it expects them to be part of a larger expression, but they are not. This causes a syntax error, and the code is not compiled.