• Post Reply Bookmark Topic Watch Topic
  • New Topic

Console.readLine in a loop - it never ends, why?  RSS feed

 
P Kowalski
Greenhorn
Posts: 18
1
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This simple program should ask for text, display it and quit if I type "q", but it doesn't quit. Anyone could please explain why?

This is what happens:

l$ java Regex1
Input?: hh
Input is: hh
Input?: q
Input is: q
Input?: ^C


At the end I just have to CTRL+C to kill it.


 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String equality is tested via the "equals" method, not via the "==" or "!=" operators.
 
P Kowalski
Greenhorn
Posts: 18
1
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course! I was so involved in a more complicated problem that this simple answer didn't even cross my mind. Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!