有没有办法使用OutOfOrder的代码,使得InOrder变得像OutOfOrder一样简单?

huangapple go评论66阅读模式
英文:

Is there a way to use the code for OutOfOrder, to make InOrder as simple as OutOfOrder?

问题

以下是翻译好的内容:

我正努力尝试仅使用逻辑规则和使用OutOfOrder代码来尝试各种方法以使InOrder尽可能简单就像OurOfOrder一样

public class InOrder {
    // 不要更改此部分
    public boolean OutOfOrder(int n1, int n2, int n3) {
        return (n1 > n2) || (n2 > n3);
    }

    // 原始混乱的InOrder,请将其保留为不应该采用的示例
    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;
        }
    }

    // 部分5的新且改进的InOrder,调用OutOfOrder
    public boolean inOrder5a(int n1, int n2, int n3) {
        return true; // 在这里替换
    }

    // 部分6的更新且改进的InOrder,内联
    public boolean inOrder5b(int n1, int n2, int n3) {
        return true; // 在这里替换
    }
}
英文:

I have having a hard time trialling methods using ONLY the rules of logic and using the OutOfOrder code, to make InOrder as simple as OurOfOrder.

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
}

//The newer and improved InOrder for part 6, inline
public boolean inOrder5b(int n1, int n2, int n3) {
return true;//replace this
}

}

答案1

得分: 1

看起来数字要么是有序的,要么是无序的,没有第三种选择。

因此,您可以将inOrder实现为:

public boolean inOrder(int n1, int n2, int n3) {
    return !outOfOrder(n1, n2, n3);
}
英文:

It seems that numbers are either in order or out of order, there is no third option.

So you can implement inOrder as:

public boolean inOrder(int n1, int n2, int n3) {
    return !outOfOrder(n1, n2, n3);
}

答案2

得分: 0

我本会说:(n2 >= n1 && n3 >= n2)

英文:

I would have said: (n2 >= n1 && n3 >= n2)

huangapple
  • 本文由 发表于 2020年9月2日 15:34:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63700779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定