我创建了我的第一个类,它有助于我为 GUI 编写的代码。但是,在执行任何操作按钮后,字符串不存在并且始终带有红色下划线,您建议如何解决此问题?换句话说,我需要整个程序能够识别这两个字符串。补充:我几乎只需要为我的二进制搜索识别这些值。
public class myFirstClass {
String refNum, title;
myFirstClass (String _refNum, String _title) {
refNum= _refNum;
title = _title;
}
}
public static Boolean binarySearch(String [ ] A, int left, int right, String V){
int middle;
refNum++; //this is underlined red which is a problem
if (left > right) {
return false;
}
middle = (left + right)/2; //everything below is fine...
int compare = V.compareTo(A[middle]);
if (compare == 0) {
return true;
}
if (compare < 0) {
return binarySearch(A, left, middle-1, V);
} else {
return binarySearch(A, middle + 1, right, V);
}
}