Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why i can't type String letter in the employee's department?

What’s wrong on my code? i can’t even resolved it

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

  1. 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

  2. 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());

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading