Scanner, useDelimiter

前端 未结 3 1438
误落风尘
误落风尘 2020-12-12 02:11

I encounter some problem when using useDelimiter from the Scanner class.

Scanner sc = new Scanner(System.in).useDelimiter(\"-\");
while(sc.hasNext())
{
    S         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 02:52

    You could use an alternative delimiter string useDelimiter( "-|\n" ); It works with a String argument as well as by reading from System.in. In case of System.in this requires you to press enter at the end of the line.

提交回复
热议问题