We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 3: Intro to Conditional Statements
You are viewing a single comment's thread. Return to all 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.