java string variable using .next() or .nextLine()

Your problem is that the line

option = scan.nextInt();

does not read the new line character after the integer. So that new line is finally read when you do nextLine(), later on.

To fix this, you should add an extra

scan.nextLine()

after the call to nextInt(), then use

cname = scan.nextLine();

when you want to read the clerk’s name.

Leave a Comment