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: Need help finding why this code doesn't work!

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

    Default Need help finding why this code doesn't work!

    I have just written this code, but it is not printing out "Working correctly!" if I input "123"... does anybody know why this is the case?

    public static void main(String[] args) {
     
            String[][] array = new String[3][3];
     
            array[1][0] = "123";
     
            Scanner scanner = new Scanner(System.in);
     
            System.out.print("Enter a number : ");
            String userEntry = scanner.nextLine();
     
            if (userEntry == array[1][0]) {
                System.out.println("Working correctly!");
            }
        }
    Last edited by MattsMan999; April 19th, 2021 at 09:24 AM. Reason: SOLVED

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,107
    Thanks
    53
    Thanked 2,618 Times in 2,568 Posts

    Default Re: Need help finding why this code doesn't work!

    Use the equals() method to compare the contents of two String objects, not the == operator.
    If you don't understand my answer, don't ignore it, ask a question.

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

    MattsMan999 (April 19th, 2021)

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. Code doesn't work
    By Nicken99 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2014, 04:24 AM
  3. Code doesn't work despite being from book
    By Math2 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 16th, 2013, 08:24 PM
  4. actionListner code doesn't work ????
    By sciences in forum AWT / Java Swing
    Replies: 4
    Last Post: February 27th, 2012, 06:46 AM
  5. File Reading code doesn't work
    By koryvandell in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2011, 08:40 AM

Tags for this Thread