Java Scanner String input

前端 未结 5 1296
遇见更好的自我
遇见更好的自我 2020-12-05 11:02

I\'m writing a program that uses an Event class, which has in it an instance of a calendar, and a description of type String. The method to create an event uses a Scanner t

5条回答
  •  攒了一身酷
    2020-12-05 11:16

    When you read in the year month day hour minutes with something like nextInt() it leaves rest of the line in the parser/buffer (even if it is blank) so when you call nextLine() you are reading the rest of this first line.

    I suggest you to use scan.next() instead of scan.nextLine().

提交回复
热议问题