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

		for (int i = 0; i < filename; i++) {
			int numofDoc = 0;
			for (int b = 0; b < array.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().equals(word2))
								matchedWord++;
						}

					}
					if (matchedWord > 0)
						numofDoc++;

					System.out.println("File containing the term is "
							+ numofDoc);

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

This file contain the term 0
This file contain the term 0
This file contain the term 1
This file contain the term 0
This file contain the term 0
This file contain the term 0
File not found.
This file contain the term 0
This file contain the term 0
This file contain the term 1
This file contain the term 1

I got this output but the output i wanted is the result prints only one line summing up all the counter.

Example : The file containing the term is 3. Only one line of print.

Any advices ?