ViceroyFizzlebottom
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.
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
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.
protected members are only accessible from subclasses.
ASKER
Any suggestion on a specific class or approach to counting the user input?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent. Thanks