File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string management

 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joyce Lee
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradyut,

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



Joyce
[ November 15, 2004: Message edited by: Joyce Lee ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic