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.
Day 3: Intro to Conditional Statements
Day 3: Intro to Conditional Statements
Sort by
recency
|
1801 Discussions
|
Please Login in order to post a comment
Easy solution!
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.
Below is the code that goes under main function:
function main() { const N = parseInt(readLine().trim(), 10); if (N % 2 !== 0) { console.log("Weird"); } else if (N >= 2 && N <= 5) { console.log("Not Weird"); } else if (N >= 6 && N <= 20) { console.log("Weird"); } else { console.log("Not Weird"); } }