gpt4 book ai didi

java - 创建一个 ArrayList,其中包含用户定义的最小值和最大值之间的一组数字(JAVA)

转载 作者:行者123 更新时间:2023-12-02 07:14:04 25 4
gpt4 key购买 nike

基本上,我需要创建一个名为:

public boolean doesContain(double x)

其工作原理如下:

Returns true if and only if x lies between left and right, and the
interval is not empty (i.e. left < right).

这就是类的样子:

public class Interval {

private double left;
private double right;

public Interval(double left, double right){
this.left = left;
this.right = right;
}

public boolean doesContain(double x){

ArrayList<Double> nums = new ArrayList<Double>();
//Add code here

}
}

最佳答案

public boolean doesContain(double x) {
if (left >= right) {
return false;
} else {
return x >= left && x <= right;
}
}

关于java - 创建一个 ArrayList,其中包含用户定义的最小值和最大值之间的一组数字(JAVA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15176086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com