I have written out the following code and my aim is to enter a string at the prompt and return any word in the list containing this string. I think I am only missing something small as when I run the program it prints the whole word list. Any help would be appreciated.
package assignment1;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
public class URLReader {
static List<String> words = new ArrayList<String>();
public static void main(String[] args) throws Exception {
System.out.println("Please Input A String");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String letters = br.readLine();
URL oracle = new URL("http://dl.dropbox.com/u/18678304/2011/BSc2/words.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
words.add(inputLine);
in.close();
for(int i = 0; i<words.size(); i++)
{
if(words.get(i).indexOf(letters) >= 0);
System.out.println(words.get(i));
}
}
}
you have a
;at the end of your if statement:it should be: