• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string management

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer to this similar thread posted by you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic