Counting characters from a ile

I need help trying to count all of the character from a file the user types in. I also need to count the number of lines, average line length, and words per line. How could i count each character so it counts the spaces also?

Comments

  • : I need help trying to count all of the character from a file the user types in. I also need to count the number of lines, average line length, and words per line. How could i count each character so it counts the spaces also?
    :
    If you read an entire line using BufferedReader.readLine(), then you have a String object containing that line. From there you can easily obtain the length, number of characters, and count the number of words.
  • I am able to count the # of chars now using nextLine(). I still doing know how i can count the # of lines. Sorry if i seem ignorant im new to java.
  • : I am able to count the # of chars now using nextLine(). I still doing know how i can count the # of lines. Sorry if i seem ignorant im new to java.
    :
    Here is the pseudo code for counting lines:
    [code]
    numberOfLines = 0;
    while (!end-of-file) do {
    reader.readLine(s);
    numberOfLines++;
    }
    system.out.println(numberOfLines);
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories