Java How to search a word from text file [closed]

Questions:

edit: Write a program to read in 100 words from a file. Then, have the user search for a word until they enter ‘quit’.
The program will read in up to 100 words from a file. The file may or may not contain 100 words but the array should hold up to 100 (if the list does not contain enough words, fill the rest of the array with empty strings).
After the file is read in, the program will prompt the user for a search string. The program will then search for the string and tell the user if the word was found or not. The program will continue to get search strings from the user until the user enters ‘quit’

Hello I need help write a program to find a word from text file

the result should look like:

Enter a word to search for: taco

Word ‘taco’ was found.

Enter a word to search for: asd

Word ‘asd’ was NOT found.

and when user enter the word “quit” the program will quit

below is what I have so far and need help to complete

import java.io.*;
import java.util.Scanner;
public class project2 {
  public static void main( String[] args ) throws IOException {
    String[] list;
    String  search;

    list = load_list( "words.txt" );
    search = prompt_user( "nEnter a word to search for: " );
    while ( ! search.equals( "quit" ) ) {
      System.out.println( "Word '" + search + "' was" +
            ( ( find_word( search, list ) ) ? "" : " NOT" ) +
            " found." );
      search = prompt_user( "nEnter a word to search for: " );
    }    
    System.out.println();
}
Answers:



Questions:

edit: Write a program to read in 100 words from a file. Then, have the user search for a word until they enter ‘quit’.
The program will read in up to 100 words from a file. The file may or may not contain 100 words but the array should hold up to 100 (if the list does not contain enough words, fill the rest of the array with empty strings).
After the file is read in, the program will prompt the user for a search string. The program will then search for the string and tell the user if the word was found or not. The program will continue to get search strings from the user until the user enters ‘quit’

Hello I need help write a program to find a word from text file

the result should look like:

Enter a word to search for: taco

Word ‘taco’ was found.

Enter a word to search for: asd

Word ‘asd’ was NOT found.

and when user enter the word “quit” the program will quit

below is what I have so far and need help to complete

import java.io.*;
import java.util.Scanner;
public class project2 {
  public static void main( String[] args ) throws IOException {
    String[] list;
    String  search;

    list = load_list( "words.txt" );
    search = prompt_user( "nEnter a word to search for: " );
    while ( ! search.equals( "quit" ) ) {
      System.out.println( "Word '" + search + "' was" +
            ( ( find_word( search, list ) ) ? "" : " NOT" ) +
            " found." );
      search = prompt_user( "nEnter a word to search for: " );
    }    
    System.out.println();
}
Answers:



Need Help? Chat with us