代码编写过程中报错The type of the expression must be an array type but it resolved to int. 说明一个int类型的变量被当作了数组类型array来处理。
检查代码:
public static int InsertValueSearch(int arr, int left, int right, int findVal) {
if( left > right || findVal < arr[0] || findVal > arr[arr.length-1]) {
return -1;
}
int mid = left + (right - left) * (findVal - arr[left])/(arr[right] - arr[left]);
int midVal = arr[mid];
发现arr初始的类型错误,改为
public static int InsertValueSearch(int[] arr, int left, int right, int findVal)
报错消失。
其他地方的这个报错应该也是相同的问题,或者是[]符号没有打对。