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 に答える