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 4065412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:58:47+00:00 2026-05-20T15:58:47+00:00

this guide is given by one of my lecturer and i wanted to implement

  • 0

this guide is given by one of my lecturer and i wanted to implement in java.
But i do not quite understand it though on how to implement in on java.
Can someone try to explain it further for me? I appreciate a good tutorial though. 🙂

“Create an array for the text file, look through each text file for the term, once you got the term, you break the inner loop, change the file name and loop again to search for the term. then create a counter to count the number of text file that contain the term. Lastly you will get the number of document containing the term from the counter value.”

I has a collection of text files where i need to check whether a specific term is found on the file. If the term is found, i need to increment the fileFound to 1.

Or more specifically inverse document frequency.

What do i need in order to achieve the above ? I mean in code perspective. Sorry, i am slow in codings. No, i do not wish for free codes. I just want to understand what the guide is given. I have asked my lecturer but it does not sufficient though. I just wanted to know how to implement in java. Thanks for your time.

System.out.println("Please enter the required word  :");
    Scanner scan2 = new Scanner(System.in);
    String word2 = scan.nextLine();
    String[] array2 = word2.split(" ");

    int numofDoc = 0;
    for (int i = 0; i < filename; i++) {

        for (int b = 0; b < array2.length; b++) {

            try {

                BufferedReader in = new BufferedReader(new FileReader(
                        "C:\\Users\\user\\fypworkspace\\TextRenderer\\abc"
                                + i + ".txt"));

                int matchedWord = 0;

                Scanner s2 = new Scanner(in);

                {
                    while (s2.hasNext()) {
                        if (s2.next().contains(word2))
                            matchedWord++;
                    }

                }
                if (matchedWord > 0)
                    numofDoc++;

                System.out.println("This file contain the term  "
                        + numofDoc);

            } catch (IOException e) {
                System.out.println("File not found.");
            }

        }

    }

The output is :

Please enter the required word :

the
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File not found
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1

i would like the output to printout single output which shows number of File containing the term is 10. It means it already sum up the total. And only print one line out in the output. Any idea sir ?

  • 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-05-20T15:58:47+00:00Added an answer on May 20, 2026 at 3:58 pm

    I just took a quick glance at your code, but it looks as if your variable ‘matchedWord’ is counting the number of words all ready. You just have to change where you define it and write the appropriate println statement at the end of your method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm using this guide but having zero luck on testing to decide whether
I have followed this guide: http://maven.apache.org/guides/plugin/guide-java-plugin-development.html I have created a maven-plugin project hello-maven-plugin with
I followed this guide here perfectly and have gone through it again but when
I was given this question on my study guide for a test I have
This is from my study guide. From my perspective this is almost done but
Given an Objective-C type type , one can obtain the encoding encoding and size
I am following this guide developer instrument guide and RayWenderlich's tutorial to view and
I have followed this guide to install Solr in TomCat running on Windows Server
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
I'm following this guide to get key binding to work in my application. So

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.