[Bluej-discuss] ex 4.19
Yves Hamel
YHAMEL at pptc.gc.ca
Mon Oct 2 13:47:26 BST 2006
I guess that "Search term not found." should be printed after you'd have searched through all the collection of notes, so you should place it after the while like this :
while(index < notes.size() && !found) {
String note = notes.get(index);
if(note.contains(searchString)) {
found = true;
System.out.println(note);
}
else {
index++;
}
}
if (!found) {
System.out.println("Search term not found.");
}
>>> John Simonds <simonj2 at sage.edu> 2006/10/01 12:57 PM >>>
I have a problem printing the search term not found. I originally placed it just before the index ++ but that did not get the desired result.
Here is the code I have written..
_/**
* Search method
*/
public void search(String searchString)
{
int index = 0;
boolean found = false;
while(index < notes.size() && !found) {
String note = notes.get(index);
if(note.contains(searchString)) {
found = true;
System.out.println(note);
}
else {
index++;
}
System.out.println("Search term not found.");
}
}
John Simonds
Systems Technologist
simonj2 at sage.edu
(518)244-3111
(518)292-1734
More information about the bluej-discuss
mailing list