dimanche 17 février 2019

Which one is better in terms of space/time complexity?

in terms of space/time complexity, which is better?

if (!(N % 2 == 0) || N % 2 == 0 && (N >= 6 && N <= 20)) {
  System.out.println("Weird");
} 
if ( N % 2 == 0 && (N >= 2 && N <= 5 || N > 20)) {
  System.out.println("Not Weird");
}

// OR

if (!(N % 2 == 0)) {
  System.out.println("Weird");
} else {
  if (N >= 2 && N <= 5) {
    System.out.println("Not Weird");
  }  if (N >= 6 && N <= 20) {
        System.out.println("Weird");
  }  if (N > 20) {
        System.out.println("Not Weird");
  }
}       

I'm trying to see whether the best way to create if statements in Java is to make simple but direct if statements such as the one below (but a bit messier) or the 'neat' one on the top. Every small detail would be appreciated.

Aucun commentaire:

Enregistrer un commentaire