I’m completely lost. I’ve googled for this problem for possibly 30 minutes now, and I can’t find any java specific solutions (or any solutions that crossover into java).
I’ve tried using the generic two simple for loops for going through each individual String, but it only seems to return results if the search term is in the first column of the array.
public static String search(String term) {
String result = "";
int row = db.bookdb.length;
for (int i=0; i<db.bookdb.length; i++) {
for (int j=0; j<4; j++) {
if (term.equals(db.bookdb[i][j])) {
row = i;
break;
}
}
}
if (row == db.bookdb.length) {
result += "Your search failed to return any results";
}
else {
for (int j=0; j<4; j++) {
result += db.bookdb[row][j] + " ";
}
}
return result;
}
db is the object i’m working with, and bookdb is the 2D array within said object. (and yes, the amount of columns will always be 4)
If there’s any additional information you guys need feel free to ask.
Your search method works fine. I created a class and used your Search method (COPIED AND PASTED, I didn’t even change your search) and it works. This leads me to believe the problem is in how you’re entering your data.
And the results:
and the results with the change:
If we use an advanced search method (which I’m calling search2) we get this:
Here’s the advanced search method: