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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:00:57+00:00 2026-05-20T18:00:57+00:00

for (a = 0; a < filename; a++) { try { System.out .println( _

  • 0
for (a = 0; a < filename; a++) {

        try {
            System.out
                    .println(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  ");
            System.out.println("\n");
            System.out.println("The word inputted : " + word2);
            File file = new File(
                    "C:\\Users\\user\\fypworkspace\\TextRenderer\\abc" + a
                            + ".txt");
            System.out.println(" _________________");

            System.out.print("| File = abc" + a + ".txt | \t\t \n");

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

                totalCount = 0;
                wordCount = 0;

                Scanner s = new Scanner(file);
                {
                    while (s.hasNext()) {
                        totalCount++;
                        if (s.next().equals(array2[i]))
                            wordCount++;

                    }

                    System.out.print(array2[i] + " --> Word count =  "
                            + "\t " + "|" + wordCount + "|");
                    System.out.print("  Total count = " + "\t " + "|"
                            + totalCount + "|");
                    System.out.printf("  Term Frequency =  | %8.4f |",
                            (double) wordCount / totalCount);

                    System.out.println("\t ");

                    double inverseTF =  Math.log10((float) numDoc
                            / (numofDoc[i]));
                    System.out.println("    --> IDF = " + inverseTF );

                    double TFIDF = (((double) wordCount / totalCount) * inverseTF);
                    System.out.println("    --> TF/IDF = " + TFIDF + "\n");





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

    }
}

This is my code to calculate the term frequency for each of the query i input inside.
Now i am trying to total each query frequency for each file.

Example output :

The number of files is this folder is : 11
Please enter the query :
how are you
how –> This number of files that contain this term 3
are –> This number of files that contain this term 7
you –> This number of files that contain this term 7


The word inputted : how are you


| File = abc0.txt |
how –> Word count = |4| Total count = |957| Term Frequency = | 0.0042 |
–> IDF = 0.5642714398516419
–> TF/IDF = 0.0023585013159943234

are –> Word count = |7| Total count = |957| Term Frequency = | 0.0073 |
–> IDF = 0.1962946357308887
–> TF/IDF = 0.00143580193324579

you –> Word count = |10| Total count = |957| Term Frequency = | 0.0104 |
–> IDF = 0.1962946357308887
–> TF/IDF = 0.002051145618922557

Example : The total frequency is 4 + 7 + 10 = 21..


The word inputted : how are you


| File = abc1.txt |
how –> Word count = |4| Total count = |959| Term Frequency = | 0.0042 |
–> IDF = 0.5642714398516419
–> TF/IDF = 0.0023535826479734803

are –> Word count = |7| Total count = |959| Term Frequency = | 0.0073 |
–> IDF = 0.1962946357308887
–> TF/IDF = 0.0014328075600794795

you –> Word count = |10| Total count = |959| Term Frequency = | 0.0104 |
–> IDF = 0.1962946357308887
–> TF/IDF = 0.002046867942970685

How can i make it to total the 3 queries WORD COUNT for each file ?

Example : The total frequency is 4 + 7 + 10 = 21..

  • 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-20T18:00:58+00:00Added an answer on May 20, 2026 at 6:00 pm

    the totalcount must be outside of your try. initialise it before your try and print it after. There are a lot concerns about the design of your Java program, I hope you will think about that stuff, too. For the time beeing, probably that should be all you need:

    for (a = 0; a < filename; a++) {
      int totalcount = 0;
      try{
        int wordcount = 0;
        for(...){
          ...
        }
        //print wordcount
        totalcount += wordcount;
      }catch(Exception e){
        ...
        return; //to ensure that there is no total count if something goes wrong.
      }
      //print totacount
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

System.out.println(Please enter the required word :); Scanner scan2 = new Scanner(System.in); String word2 =
//Count the number of documents available File folder = new File(C:\\Users\\user\\fypworkspace\\TextRenderer); File[] listOfFiles =
// Calculating term frequency System.out.println(Please enter the required word :); Scanner scan = new
// Calculating term frequency System.out.println(Please enter the required word :); Scanner scan = new
System.out.println(Please enter the required word :); Scanner scan = new Scanner(System.in); String word =
When i try to specify an absolute path for the generated files using someTemplate.RenderToFile(c:\\tmp\\filename.ext);
public static Reservation[] openBinaryFile( String fileName ) { Reservation [] objArray = null; try
I am currently using PIL. from PIL import Image try: im = Image.open(filename) #
I have a filename in a format like: system-source-yyyymmdd.dat I'd like to be able
I have a filename that has the following format: timestamp-username-1 This file is constantly

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.