Asked
Active
Viewed 87 times
-3
-
Does this answer your question? [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – sittsering Nov 13 '21 at 04:12
-
2and do not post images of codes and errors. Post them as text. – sittsering Nov 13 '21 at 04:13
1 Answers
0
This is a classic issue. When you read nextDouble(), the enter character at the end of the double will not be read in the double itself, but the next nextLine() will just read that enter character and will not allow you to type anything.
For your particular code, there are 2 ways to fix it
change the department and salary order, so that salary will be the last thing to read. Since you are not reading data in a loop, this should do it
If you want to read data in a loop, then only good solution will be read salary as nextLine() too, and use Double.parseDouble() to parse it to double. As
double salary = Double.parseDouble(in.nextLine());

Binayak
- 96
- 2