wood burning stoves 2.0*
The moose likes Java in General and the fly likes string management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "string management" Watch "string management" New topic
Author

string management

Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
hi friends,

i have a problem on managing input strings on a program.

i have to make a program in which on hitting "enter" or a particular word the program should show some output.

the code of my program: -

--------------------------------------------------------
import java.lang.*;
import java.util.*;
import java.io.*;

public class test
{

public static void main(String args[])
{
try
{
//ctrl-c to terminate the program
while(true)
{
InputStreamReader keyreader = new InputStreamReader(System.in);
BufferedReader bfreader = new BufferedReader(keyreader);
System.out.println("Enter the element: ");
String name = bfreader.readLine();
if (name == "test")
System.out.println("this is a test");
else if (name == "")
System.exit(0);
else
System.out.println(name);
}
}
catch(Exception e)
{
System.err.println(e);
}
}
}
---------------------------------------------------------------

here on giving the word test or simply hitting enter the program does not show the results as required.

any help
thanks
Pradyut


Pradyut
http://pradyut.tk/
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Pradyut,

You must use the equals() method to compare the String content.



Joyce
[ November 15, 2004: Message edited by: Joyce Lee ]
 
 
subject: string management