Scanner is not reading the whole sentence sentence

前端 未结 2 1468
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 10:31

Scanner is not reading the whole sentence. Or let\'s say I\'m writing a method which reverses the words in a sentence while keeping them in their order in a sentence.

         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 11:23

    you need to use nextline() function instead of next() to capture the whole line Change String s= scanner.nextLine(); instead of String s= scanner.next();

提交回复
热议问题