英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论