java.util.scanner

Scanner is skipping nextLine() after using next() or nextFoo()?

我是研究僧i 提交于 2019-11-25 21:30:12
问题 I am using the Scanner methods nextInt() and nextLine() for reading input. It looks like this: System.out.println(\"Enter numerical value\"); int option; option = input.nextInt(); // Read numerical value from input System.out.println(\"Enter 1st string\"); String string1 = input.nextLine(); // Read 1st string (this is skipped) System.out.println(\"Enter 2nd string\"); String string2 = input.nextLine(); // Read 2nd string (this appears right after reading numerical value) The problem is that