所以我的代码没有错误,但由于某种原因,无论数组是否包含它,我的搜索都会返回真实结果
public static void linSrch(String[] names) {
Scanner inputDevice = new Scanner(System. in );
System.out.println("Please enter search");
String search;
search = inputDevice.nextLine();
boolean searchReturn;
for (int index = 0; index < names.length - 1; index++) {
if (names[index] == search) {
searchReturn = true;
}
}
if (searchReturn = true) {
System.out.println(search + " is found in the array.");
} else {
System.out.println(search + " not found in the array");
}
}