1-he enters nothing and presses only enter. OR if this is not possible,
2-he enters "exit".
What is the code to be put inside the while loop below for the above cases to happen ?
I tried has next , has next line , !has next("exit") and failed. Please tell me how to proceed.
thanks for the hint.
PS : here is another problem i had long ago while using the Scanner class :
Campbell Ritchie wrote:I don't like break; myself. The idiom for that sort of thing in the heading of a while loop is not the sort of thing you can work out unless you have seen it. Try this sort of thingYou can add a second test with the && operator, but don't call nextLine() twice.
Love you man... . By the way, what is an "idiom" saw it in the sun docs too, just ignored it and there was no loss of continuity.
Here is the revised program :
sample output :
This code works fine if you enter each sentence word by word (as shown below) :
But it obviously fails when the input is given as below :
How to resolve the above problem. Will it require major rewriting of code ?
thanks for hearing
Yes. You would have to change nextLine() to next()
Rahul Sudip Bose wrote: . . . Will it require major rewriting of code ? . . .
You might have to enter ctrl-D or ctrl-Z to terminate entry if you use that technique, and use hasNext() to continue with the loop.
And an idiom is something that is said in a particular context, which would otherwise appear incorrect. It is a linguistic term. An example of an English idiom is "raining cats and dogs".