Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: find a password

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default find a password

    int nElems=10;
    int i;
    String A[]=new String [nElems];
    System.out.println("Write 10 passwords");
    for (i=0;i<10;i++)
    {
    A[i]=entrada.next();
    }

    String searchKey;
    System.out.println("Give me your password");
    searchKey=entrada.next();

    for(i=0;i<nElems;i++)
    if(A[i]==searchKey)
    break;
    if(i==nElems)
    System.out.println("Incorrect");
    else
    System.out.println("Correct");


    please what´s wrong?? it always print "incorrect" though the password is there.!!!


  2. #2
    Member
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    54
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: find a password

    Try replacing the == with equals(searchKey), that should fix the problem. If you don't care whether letters are upper or lower case, you can instead use equalsIgnoreCase(searchKey).

  3. The Following User Says Thank You to SunshineInABag For This Useful Post:

    barbiie (April 8th, 2013)

Similar Threads

  1. [SOLVED] Help with password generation
    By Dr.Code in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 25th, 2012, 06:36 AM
  2. Random Password
    By qwerty53 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 19th, 2011, 02:46 AM
  3. Using a password field
    By javapenguin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 10th, 2010, 10:54 AM
  4. Find the password with dictionary attack
    By mortis1572 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 19th, 2010, 09:07 PM
  5. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM