我编写了这个递归方法来查找整数数组中的整数,但它不起作用。我尝试调试它,但我不知道问题可能是什么。
这是代码
public static String inList(int[] primes,int a){
int index = -9;
if(primes.length>1){
index = primes.length/2;
}else{
if(primes[0] == a){
return "True";
}else{
return "False";
}
}
if(primes[index] == a){
return "True";
}
if(primes[index] > a){
inList(Arrays.copyOfRange(primes, 0, index),a);
}
if(primes[index]<a){
inList(Arrays.copyOfRange(primes, index, primes.length),a);
}
//shouldn't even get to this point, but eclipse insisted I needed another return
//statement
return "Whyyyyy?";
}