Results 1 to 2 of 2
  1. #1
    jaq
    jaq is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Post need in help in comparing Strings

    hi all...

    i have assigned two values for name1 and name2 and I am comparing it with the input name....

    the issue i face is that what ever name i give Iam able to get the out put as First only.Not as "Second" and "No".

    Here is my code.


    import java.io.*;
    public class hello {
    public static void main(String args[]) throws IOException {
    String name1="sam";
    String name2="pal";
    BufferedReader name;

    name = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the name :");
    try{
    name.readLine();
    if(!name.equals(name1))
    System.out.println("First");

    else if(!name.equals(name2))
    System.out.println("Second");

    else
    System.out.println("No");
    }
    catch(IOException e){
    System.out.println("IO exception");
    }
    }
    }


    can any one pls help..

    thanks in advance.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Because you need to assign the result of that name.readLine to a variable and use that variable in your if statements. name is a BufferedReader not a String.

Similar Threads

  1. homework help comparing strings
    By djester55 in forum New To Java
    Replies: 2
    Last Post: 10-19-2009, 10:15 PM
  2. comparing strings
    By diggitydoggz in forum New To Java
    Replies: 7
    Last Post: 12-23-2008, 04:40 AM
  3. Problem Comparing Strings (its not what you think)
    By hilather in forum New To Java
    Replies: 7
    Last Post: 11-19-2008, 06:43 PM
  4. Comparing Strings
    By souFrag in forum Advanced Java
    Replies: 5
    Last Post: 05-21-2008, 09:03 AM
  5. Comparing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •