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.
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();