import java.io.*; public class StatAna { // ************************************************************ // * * // * main Method * // * * // ************************************************************ public static void main(String[] args) throws Exception { System.out.println("\n * * * Welcome to the Program * * * \n"); /*CALL*/ readHeadFile(); System.out.println("\n * * * End of the StatAna * * * \n"); } // ************************************************************ // * * // * readHeadFile Method * // * * // ************************************************************ public static void readHeadFile() { String headLineSt=""; try // Read the INPUT FILE { FileReader inputFileReader = new FileReader("Hwordscounts.txt"); BufferedReader inputFileBuffer = new BufferedReader(inputFileReader); while(true) // Until the end of the input file { headLineSt=inputFileBuffer.readLine(); if(headLineSt==null) // End of the input file { break; } // System.out.println(headLineSt); /*CALL*/ readBodyFile(headLineSt); } // End of the WHILE loop (End of the file) inputFileReader.close(); } // End of the TRY catch(FileNotFoundException e) { System.out.println("Unable to Open INPUT File"); } catch(IOException e) { System.out.println("Unable to Close INPUT File"); } } // ************************************************************ // * * // * readBodyFile Method * // * * // ************************************************************ public static void readBodyFile(String headLineSt) { char tempChar; int i=0; int counter=0; int index=0; String bodyLineSt=""; String heading=""; while(true) { tempChar=headLineSt.charAt(i); i++; if(!(48<=tempChar && tempChar<=57) && tempChar!=32) // 1 to 9 and Space { break; } } heading=heading+tempChar; // System.out.println(heading); while(true) { tempChar=headLineSt.charAt(i); i++; if(tempChar == 32 || tempChar == 10) { break; } heading=heading+tempChar; } // System.out.println(heading); heading=(char)32+heading; try // Read the INPUT FILE { FileReader inputFileReader = new FileReader("Bwordscounts.txt"); BufferedReader inputFileBuffer = new BufferedReader(inputFileReader); while(true) // Until the end of the input file { bodyLineSt=inputFileBuffer.readLine(); counter ++; if(bodyLineSt==null) // End of the input file { if(index == -1) // Did not find the word { System.out.println("NOT"); } break; } // System.out.println(bodyLineSt); index = bodyLineSt.indexOf(heading); if (index != -1) // Find the word { // System.out.println("Counter = "+counter+" <---> Heading = "+heading); System.out.println(counter); break; } } // End of the WHILE loop (End of the file) inputFileReader.close(); } // End of the TRY catch(FileNotFoundException e) { System.out.println("Unable to Open INPUT File"); } catch(IOException e) { System.out.println("Unable to Close INPUT File"); } } // ************************************************************ // ************************************************************ // ********************End Of the Program********************** // ************************************************************ // ************************************************************ }