How in the piece of the following code to allow not to enter middleName ? When I just press Enter, the transition to the next action does not occur.
Scanner in = new Scanner(System.in); String name; String surname; String middleName; String address; String joinDate; System.out.print("Add new employee\nEnter employee name: "); name = in.next(); System.out.print("Enter employee surname: "); surname = in.next(); System.out.print("Enter employee middle name: "); middleName = in.next(); System.out.print("Enter employee address: "); address = in.next(); this code didn't help
if (in.hasNextLine()) { middleName = in.next(); } else { middleName = null; }
разрешить не вводить? that is, just enter the person clicked and went to enter the address? or to give somewhere the opportunity to not even go to the itementer employee middle name? - Alexey Shimansky