Link to home
Start Free TrialLog in
Avatar of ViceroyFizzlebottom
ViceroyFizzlebottomFlag for United States of America

asked on

Counting number of characters entered by user at console window

Thanks in advance for any help.
I'm trying to get the number of characters a user has typed. I tried the following:
import java.util.*;
import java.io.*;

public class BufferSize
{
  public static void main(String[] args)
  {
    int numChars = 0;
    BufferedInputStream in = new BufferedInputStream(System.in);
     try
     {
        in.read();
     }
     catch (IOException e)
     {
     }
     finally
     {
       numChars = in.count;
     }
      System.out.printf("Number of characters: \n", numChars);
    }
}

The compiler gripes that count is a protected member of BufferedInuputStream class. Now, I thought that protected meant that if I created
an instance of the class, then my instance would have access to the variable. Some clarification on this would be helpful as well as
any advice on getting that character count with or without using the BufferedInputStream.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

protected members are only accessible from subclasses.
Avatar of ViceroyFizzlebottom

ASKER

Any suggestion on a specific class or approach to counting the user input?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent. Thanks