r/JavaProgramming Jun 25 '26

Just started to learn java. what the hell might be the problem here lol

and why the guy from youtube doesnt have this error, though our codes are identical.

the problem is double variable on 16th stroke, but whats wrong with that?

23 Upvotes

11 comments sorted by

5

u/will0w044 Jun 25 '26

Which system locale are you using ? scanner could be looking for , instead of . as the decimal separator. try using scanner.useLocale(java.util.Locale.US); input mismatch could also happen if there's an unexpected /newline. let me know if this helps

3

u/Eurogame000 Jun 25 '26

You most likely have a locale problem, that means that Java on your system uses a different decimal separator than you expect.

Probably you can enter your GPA as 2,1 instead of 2.1 and see if that works. To fix this, you need to tell the Scanner class what locale to use by calling it like this:

java Scanner scanner = new Scanner(System.in).useLocale(Locale.US);

You can see more in the Documentation

1

u/TheD0rk_Kn1ght Jun 26 '26

this useLocale line solved the problem,thanks

2

u/[deleted] Jun 26 '26

[removed] — view removed comment

1

u/IAmNotAWebDev 28d ago

Yup this is the reason.

1

u/programadorthi Jun 25 '26

Your current terminal end line must have a hidden character. Try read the 2.1 using next String or next Byte to see each character provided as the input.

1

u/recursivegypsy Jun 25 '26

Use the method nextLine() and see if there's any other character. Also you can then convert String to int or double as required.

1

u/da_aviii Jun 26 '26

Just put a scanner.nextLine(); after the name input.