mardi 1 septembre 2020

How Can I Further Simplify the InOrder code by making just one call to OutofOrder?

Having trouble trying to find a way to simplify the inOrder code so that it makes just one singular call to OutofOrder. I am having difficulty trying to find a way to make the call...

public class InOrder {
//Don't change this
public boolean OutOfOrder(int n1, int n2, int n3) {
return (n1 > n2) || (n2 > n3);
}

//The original and messy InOrder, leave this as an example of what not to do
public boolean inOrder(int n1, int n2, int n3) {
if (n2 > n1) {
  if (n3 > n2) {
    return true;
  } else {
    return false;
  }
} else if (n2 == n1) {
  if (n3 == n1) {
    return true;
  } else {
    return false;
  }
} else {
  return false;
}
}

//The new and improved InOrder for part 5, call OutOfOrder
public boolean inOrder5a(int n1, int n2, int n3) {
return true; //replace this
}
}

Aucun commentaire:

Enregistrer un commentaire