This experiment and Fan classmate knot to complete.
This program in the last program slightly modified, to increase the function of search words, the main code is as follows:
Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); System.out.println ("Please enter the word you want to find"); String m=In.nextline (); intCount=0; Try{FileReader FR1=NewFileReader ("Gone_with_the_wind.txt");//ReadBufferedReader bf1=NewBufferedReader (FR1); String Str=NULL; while((Str=bf1.readline ())! =NULL) {str=str.replace ("\\n", "" "); STR=str.tolowercase (); STR=str.replaceall ("[\\pP '" ""] "," "); String[] str1=str.split (""); for(inti=0;i<str1.length;i++) { if(M.equals (Str1[i])) count++; }} fr1.close (); Bf1.close (); }Catch(Exception e) {e.printstacktrace ();} Try{FileWriter FW=NewFileWriter ("Result1.txt"); BufferedWriter BW=NewBufferedWriter (FW); Bw.write (M+"="+count); Bw.close (); Fw.close (); }Catch(Exception e) {e.printstacktrace ();} } }
Experimental data:
I searched for 3 words, which with has, and compared to the last result
Consistent results
GitHub Address: Https://github.com/sunhongyi1996/repository
Job 4.2