I am having a problem with Q2 from the aborted evening class exam. When I run the code below it hangs at the end of the line and I have to reboot but if I enter the same code from a text file it runs perfectly. It seems that hasNext() will not switch to false because of the carraige return when you enter the sentence. Has anybody found a way around this or a better way of doing it???
Scanner scan = new Scanner(System.in);
int count = 0;
while(scan.hasNext())
{
String temp = scan.next();
if(temp.length() > 1)
{
count++
}
}
System.out.println (count);
All suggestions welcome!
Thanks
Joe
