Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:38:33+00:00 2026-06-09T08:38:33+00:00

I have written out the following code and my aim is to enter a

  • 0

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));
}

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:38:34+00:00Added an answer on June 9, 2026 at 8:38 am

    you have a ; at the end of your if statement:

    if(words.get(i).indexOf(letters) >= 0);
        System.out.println(words.get(i));
    

    it should be:

    if(words.get(i).indexOf(letters) >= 0)
        System.out.println(words.get(i));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code to find out the missing sequence but i
I have the following code: var items = new List<string> {1, 2, 3}; //
I have written the following code and not able to figure out the errors
I have written the following code: library(ggplot2) data <- structure(list(x = c(1L, 6L, 3L,
I am trying out GWT in this 'configuration': 1) I have written a server
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I have written the following code. I know that a higher order function is
I have written the following code to perform some simultaneous HTTP posting and file
I have written the following code to write to a file on external storage:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.