Get input from the user till he type quit
I'm trying to write little program that get input from the user (using BufferedReader and readLine() function) the program should run till the user type 'quit'.
so i write something like this
System.out.println("Enter first number: (or type quit to exit program) ");
if(br.readLine() == "quit")
The problem is that br.readLine() == "quit" doesn't working...
when I type quit or something else the program always go to the else...
Where is my mistake?
Re: Get input from the user till he type quit
Your mistake - a common one - is in using the equals operator, '==', rather than the equals() method to compare Strings.
Another construct to accomplish the same thing, perhaps simpler, is a do/while loop:
// get user input
while( !input.equals( "quit" ) );