小编nkh*_*kar的帖子

Eclipse 给出关于不返回整数的错误

以下代码应该对卡片数组中的卡片进行递归二分搜索。Eclipse 给出一个错误,指出该方法不返回整数。

public static int binaryrSearch(Card[] cards, Card target , int low , int high)
{
    if (high<low)
    {
        return -1;
    }
    int mid = (low+high)/2;
    int comp = cards[mid].compareTo(target);
    if(comp==0)
    {
        return mid;
    }else if(comp<0)
    {
        return binaryrSearch(cards , target , mid+1 , high);
    }else if (comp>0)
    {
        return binaryrSearch(cards , target , low , mid-1);
    }
}
Run Code Online (Sandbox Code Playgroud)

比较方法:

public int compareTo(Card that){
    if(this.suit<that.suit)
    {
        return -1;
    }
    if(this.suit>that.suit)
    {
        return 1;
    }
    if(this.rank<that.rank)
    {
        return -1;
    }
    if(this.rank>that.rank) …
Run Code Online (Sandbox Code Playgroud)

java arrays recursion binary-search

2
推荐指数
1
解决办法
53
查看次数

标签 统计

arrays ×1

binary-search ×1

java ×1

recursion ×1