Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    80
    Rep Power
    0

    Unhappy Problem with the result of the implementation

    Java Code:
    import java.io.*;
    
    public class Author{
    	public static void main(String[] args)throws IOException{
    
    	BufferedReader in = new BufferedReader(new InputStreamReader (System.in));
    
    	System.out.println("Welcome in Management Program");
    	System.out.println("Please, Enter your name: ");
    	String a = in.readLine();
    	if (a == "[COLOR="Red"]AhmedHello
    
    It's my pleasure to join you in this forum
    
    Actually, I'm new in programming by Java 
    
    Yesterady, I wrote this code 
    
    "){
    		System.out.println("Welcome Mr."+ a);
    		}else{
    	System.out.println("Wrong name !!");
    	}
    }
    }
    The problem with the result of implementation

    When I implement the program and enter the same name (Ahmed) , the result will be "Wrong name"

    So, what do you think the problem is ?

    I hope you can help me

    My regards

    :)[/COLOR]

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Java Code:
    if (a == "Ahmed"){

    That should be

    Java Code:
    if(a.equals("Ahmed")) {
    equals() is a method of the String class that checks if two strings are made up of the same sequence of letters.

    == does something else. It checks whether both sides reference exactly the same object. Two strings can be different and yet have consist of the same sequence of letters: think "this book has 10000 words in it (measured by ==)" versus "But it only has 5000 words in it (measured by equals())".

  3. #3
    Join Date
    Jan 2010
    Posts
    80
    Rep Power
    0

    Default

    Thank you for your replying and helping me

    I really appreciate that

    :)
    Last edited by ŖΫ ỏ Ңόρę; 01-11-2010 at 04:47 AM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It works fine for me once changed as pbrockway recommends.

    One side favor: could you please not center-format your posts? They are hard to read when in non-standard format. Thanks.

  5. #5
    Join Date
    Jan 2010
    Posts
    80
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    It works fine for me once changed as pbrockway recommends.

    One side favor: could you please not center-format your posts? They are hard to read when in non-standard format. Thanks.
    Hi Mr.Fubarable

    I will work with what you told me

    :)

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Thank you for your replying and helping me
    I really appreciate that

    You're welcome.

Similar Threads

  1. SQLite Result Set problem
    By nikosa in forum JDBC
    Replies: 4
    Last Post: 01-25-2010, 08:53 AM
  2. Strange JSTL recordset result problem (Question)
    By jeremy.wilson in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 01-07-2010, 07:04 PM
  3. problem in get result than SQL to jtable
    By MS_Dark in forum New To Java
    Replies: 0
    Last Post: 12-13-2008, 01:52 PM
  4. problem with displaying result..
    By SCS17 in forum New To Java
    Replies: 4
    Last Post: 04-23-2008, 12:19 PM
  5. Problem in file implementation
    By BHCluster in forum New To Java
    Replies: 6
    Last Post: 04-21-2008, 04:21 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
  •