-1

I am trying to get the next char for my scanner.

My constructor is :

    public S(InputStream inStream)
    {
        in = new BufferedReader(new InputStreamReader(inStream));
        e = false;  // if input stream is done
        getNextChar(); 
    }

my method is:.

private void getNextChar()
{
       int data = in.read(); 
       char temp = char (data);
       currentChar = temp;
}

I am getting a '.class' expected error in "getNextChar()"

Any ideas why?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Surz
  • 984
  • 3
  • 11
  • 36

2 Answers2

1

Personally, I wonder why you have a void get method. Then I see two unnecessary temporaries and a worrisome attempt at casting,

private void getNextChar() {
   int data = in.read(); 
   char temp = char (data);
   currentChar = temp;
}

Assuming you really want to also set currentChar you can do something like

private char getNextChar() {
  return currentChar = (char) in.read(); // <-- chaining assignment
}

or perhaps (equivalent to the chaining version),

private char getNextChar() {
  currentChar = (char) in.read();
  return currentChat;
}

or the far more typical case would be to skip currentChar altogether,

private char getNextChar() {
  return (char) in.read();
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0
private void getNextChar() throws IOException
{
    int data = in.read(); 
    char temp = (char) data;
    currentChar = temp;
}

casting should be done like this: char temp = (char) data;

Not like this: char temp = char (data);

Raja CSP
  • 172
  • 7