java - My program prints 0 as the Output all the time dispite that there are specific Words. I am trying to count the number of specif words in a document -
java - My program prints 0 as the Output all the time dispite that there are specific Words. I am trying to count the number of specif words in a document -
paste source here:
add new lines after "{" , before "}" add together new lines before "{" remove empty lines. add together comment lines before function. add together new lines after ";" add together new lines after "}" (for .css) (thanks david) remove new lines (useful if add together them 1 time again other functions above) add together new lines after ";" not in loops (don't check "remove new lines" check "remove empty lines")(thanks chris) (experimental, uses heuristic might fail ) add together new lines after ";" not in loops , skip quotes (don't check "remove new lines" check "remove empty lines") (thanks chris) (experimental, uses heuristic might fail ) cut down whitespace set code 1 time again in input box above after submit. skip html, give me plain code! (use save-as function of browser)
import java.io.*; public class countingwords { public static void main(string[]args) throws ioexception { int count; seek (bufferedreader in = new bufferedreader(new filereader(""/home/dinesh/documents/sd1/textfile"))) { string chkword; string targetword = "a"; count = 0; while ((chkword = in.readline()) != null) { if (chkword.contentequals(targetword)) count++; } system.out.println(count++); in.close(); } } }
the file found keeps printing zero. beginner in java. give thanks you
you testing whether entire line equal word searching for. work if file scanning has like:
abcd xyz
it trigger on if have abcd xyz efg qrs
then not match. think need either regular expressions or utilize loop calls
int indexof(string str, int fromindex)
(initially fromindex = 0, next iteration of loop utilize lastindex + str.length() or lastindex + 1)
java
Comments
Post a Comment