Import java. util. hashmap;
/**
* An English sentence is separated by spaces. It intercepts words and calculates the number of times each word appears in the current English sentence.
*
* @ Author ydj
*
*/
Public class interceptwordandcountword {
Private string S;
Private hashmap <integer, string> map;
Public interceptwordandcountword (string s ){
This. S = S + "";
Map = new hashmap <integer, string> ();
}
Private void processmothed (){//This method is too inefficient
System. Out. println ("this English sentence is:" + S + "/T Length:" + S. Length ());
Stringbuffer strbuff = new stringbuffer ();
For (INT I = 0, j = 0; I <S. Length (); I ++ ){
Char c = S. charat (I );
If (C! = "". Charat (0 )){
Strbuff = strbuff. append (C );
} Else {
Map. Put (J, strbuff. tostring ());
Strbuff = new stringbuffer ();
J ++;
Continue;
}
}
For (INT I = 0; I <map. Size (); I ++ ){
Int COUNT = 0;
String S = map. Get (I );
For (Int J = 0; j <map. Size (); j ++ ){
If (S. Equals (Map. Get (j ))){
Count + = 1;
}
}
System. Out. println ("word" + S + "appears in this sentence" + Count + "times ");
}
}
Public static void main (string ARGs []) {
New interceptwordandcountword ("Hello word Hello Friend hello gril welcome to Beijing"). processmothed ();
}
}