Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Why this doesn't work??

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class brr {
public static void main(String args[])
throws IOException
BufferedReader br = newBufferedReader(new InputStreamReader(;
String c;
System.out.println("enter lines, 'stop' to quit ");
} while(c!="stop");
When executing this pgm, it doesn't stop even when i enter 'stop', but the same pgm works if i use the following statement
"while (!c.equals("stop"));" instead of "while(c!="stop");". Logically I thought that both the statements were same, but they don't work. Please explain.
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually u r using c as a string so u have to use String comparison method .equals to compare the two values .but when u r comparing as c!="stop" its not comparing the two string's data but as two objects hence its value is not true & the program doesn't stop.
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic