0

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

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

    }
}
4

2 回答 2

1
public boolean doesContain(double x){
    return left < right && left <= x && x <= right;
}
于 2013-03-02T15:25:35.027 回答
1
public boolean doesContain(double x) {
    if (left >= right) {
        return false;
    } else {
        return x >= left && x <= right;
    }
}
于 2013-03-02T15:28:09.723 回答