Conditional Statement on Java7

You’re mixing up && and ||, so your first if will never run as mentioned in the comments.

So it looks like the only "Not Weird" print out is 2, 4 and even numbers > 20.

So use this to your advantage to just check for the "Weird" outputs, otherwise print "Not Weird".

if (n % 2 == 0) {
    if ((n >= 2 && n <= 5) || (n > 20)) {
        return "Not Weird";
    }
}
return "Weird";

Online Demo

Having said this, I’m not sure what you want with Scanner::skip

Leave a Comment