The problem is here:
a= kb.nextDouble(); operator = kb.nextLine(); b = kb.nextDouble();
Getting the first
nextDouble() reads up to the next delimiter (which means whitespace), but leaves that delimiter in the stream to be read again later. Then
kb.nextLine() reads and returns everything up to the end of the line, which includes the delimiter. So
operator must start with whitespace; there is no way to enter an operator without putting some whitespace between it and the first number; the first
kb.nextDouble() will always throw an exception when you try.
Why not use
next() instead of
nextLine()? That way
kb will take care of the whitespace for you.
worked, something so simple Thanks!