Hi
i have a trouble in this code.i want the postion of the unique word occured in several times.
CODE
import java.io.*;
import java.util.StringTokenizer;
public class WordCount4{
private static void linecount(String fName, BufferedReader in) throws IOException{
long numLine=0;
long numWords = 0;
String line;
do{
line = in.readLine();
if (line != null){
numWords += wordcount(line);
numLine++;
}
}while(line != null);
System.out.println("Number of words: " + numWords);
System.out.println("Number of Lines: " + numLine);
}
private static long wordcount(String line){
long numWords = 0;
/* int index = 0;
boolean prevWhiteSpace = true;
while(index < line.length()){
char c = line.charAt(index++);
boolean currWhiteSpace = Character.isWhitespace(c);
if(prevWhiteSpace && !currWhiteSpace){
numWords++;
}
prevWhiteSpace = currWhiteSpace;
}*/
return numWords;
}
public static void main(String[] args){
long numLine=0;
String line;
try{
if (args.length == 0)
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
line = in.readLine();
String reqword="is";
int reqWordCount=0;
StringTokenizer st = new StringTokenizer(line," ");
int count = 0;
int charcount=-1;
while(st.hasMoreElements()){
String word = st.nextToken();
count++;
charcount=charcount+word.length()+1;
if(word.equalsIgnoreCase(reqword))
{
reqWordCount++;
System.out.println("pos"+(charcount-reqword.length()));
}
//System.out.println("word:"+word+" Char Count:"+word.length()+" Word No:"+count);
}
System.out.println("The word 'is' occures "+reqWordCount+" times");
}
}
catch(IOException e){
e.printStackTrace();
}
}
}