下面java代码运行时提示search():This method must return a result of type int,程序该如何改public class ArraySerachtest {public static int search(int[] array,int value){int low=0;int high=array.length-1;int middle=0;//value值为两
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/19 14:27:55
下面java代码运行时提示search():This method must return a result of type int,程序该如何改public class ArraySerachtest {public static int search(int[] array,int value){int low=0;int high=array.length-1;int middle=0;//value值为两
下面java代码运行时提示search():This method must return a result of type int,程序该如何改
public class ArraySerachtest {
public static int search(int[] array,int value)
{
int low=0;
int high=array.length-1;
int middle=0;
//value值为两边
if(value==array[0])
return 0;
if(value==array[high])
return high;
//value值不在数组中
if(valuearray[high])
return -1;
//value值在数组中
while(lowarray[middle])
low=array[middle+1];
else if(value
下面java代码运行时提示search():This method must return a result of type int,程序该如何改public class ArraySerachtest {public static int search(int[] array,int value){int low=0;int high=array.length-1;int middle=0;//value值为两
在while循环结束后加一行:return 0;(或别的int类型的值)
就可以了.需要返回值的方法,一定要注意让返回语句覆盖每一个分支,直到方法的最后,否则就会报你说的那种错.