Classifying integers as "weird" or "not weird" Problem Statement


  Given an integer N, perform the following conditional actions:
  
  
  If N is odd, print Weird
  If N is even and in the inclusive range of 2 to 5, print Not Weird
  If N is even and in the inclusive range of 6 to 20, print Weird
  If N is even and greater than 20, print Not Weird
  
  
  Complete the stub code provided in your editor to print whether or not
  N is weird.
  
  Input Format: A single line containing a positive integer, N.
  
  Constraints: 1&lt;=N&lt;=100
  
  Output Format: Print Weird if the number is weird; otherwise, print
  Not Weird.


My Solution

if(N%2!=0)
    System.out.println("Weird");
else{
            if(N&gt;=2&amp;&amp;N&lt;=5||N&gt;20)
            System.out.println("Not Weird");
            else
            System.out.println("Weird");
        }


Another Solution-

if(N%2==1)
            System.out.println("Weird");
        else
            {
            if(N&gt;=2&amp;&amp;N&lt;=5)
                System.out.println("Not Weird");
            else if(N&lt;=20)
                System.out.println("Weird");
                else
                System.out.println("Not Weird");
        }


My question is, does one algorithm have better performance than the other, in other words, is there any advantage to using else if statements rather than logical operators. 

P.S- I am new to coding in Java, and was just curious if there is an optimum way to write code that has better performance.
In addition to the things dfhwze already mentioned:


You should separate calculation and output. Even the shorter solution mentioned by dfhwze contains a repetition of the output code (System.out.println) and the output message ("Not weird"). Furthermore, thinking on to real world problems, code that only outputs something is really hard to unit-test.


Thus, do something like:

private static boolean isWeird(int n) {
   return (n % 2 != 0) || (n &gt;= 6 &amp;&amp; n &lt;= 20); // or however you want to do the calculation
}

... // and in main:
boolean weird = isWeird(n);
if (weird) {
   System.out.println("Weird");
}
else {
   System.out.println("Not Weird");
}



One missing convention: variables should start with a lowecase character: N should be renamed to n