Hi everyone, I'm new to java and I'm taking a computer science class just for fun.
When completing an assignment that required the use of Scanner I came across a problem that I can't find a solution to.
I had to use scanner to receive input from the user for a formula and everything compiled and worked correctly except when I entered a double into the Scanner, it only accepts ints and gives me this error every time I enter a double:
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
I know that you usually get that error when the Scanner expects something else that is different from what you type and I have looked over my code time and time again and cannot find anything. I created a test program to see if it was just that problem and not something else in the code and I still got the same error but when I tried compiling and running it here browxy.com everything worked and I got the right answer for the formula. Here's the test I used:
At this point I'm thinking it might be a problem with my install of DrJava and I've tried re-installing but nothing changed. Can anyone help?
Hello Ron, would you mind please making a new post when replying to a thread rather than updating your existing post. Think of this as a conversation. Going back and changing something you've already said can make the conversation confusing at best, and at worst can make the posts after yours look like nonsense if they're referring to something you said before you edited it.
Edit: Ron, Your previous reply came in at the same time as I posted this one. I take it back. You know the score.
I hadn't even thought of that, yes it works with 1,2. I think my professor always uses . instead of , though. I think in other cases it always accepts . when using a double. Using the scanner is the first issue I've had with this.
Added, I didn't know it used my windows language I should have assumed that. My windows is Portuguese so it gives me:
Decimal separator: , Can I change it to English?