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.
Well even I added n%2==0 condition but we do not need to.
As it has been said that if n is odd it is weird and if even numbers between 6-20 are weird then it doesnt matter that the number is even or odd in 6-20 as odd numbers are already weird with the condition n%2==1.
So we can have if(n%2==1 || (n>=6 && n<=20)) for the weird condition.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java If-Else
You are viewing a single comment's thread. Return to all comments →
Well even I added n%2==0 condition but we do not need to. As it has been said that if n is odd it is weird and if even numbers between 6-20 are weird then it doesnt matter that the number is even or odd in 6-20 as odd numbers are already weird with the condition n%2==1. So we can have if(n%2==1 || (n>=6 && n<=20)) for the weird condition.