-1

I am trying to create parallel arrays that will hold 4 names, 4 pass codes for a login page for an android app. I must use arrays for this particular part. Here is some of the code I have been working with in java, but I am not sure how to bring this into app itself in the OnCreate page. I will have to make amendments to the code to bring it into the emulator so any suggestions would be greatly appreciated. Note: I intend to use a drop down box to show the 4 user names.

        // System.out.println("Enter name");
        //String name = keyboard.nextLine(); //user enters name
        System.out.println("Enter pass code");
        int passcode = keyboard.nextInt();

        String[] names = {"User1", "User2", "User3", "User4"};
        int[] passcodes = {1234, 4321, 5678, 8765};

        for (int i = 0; i < names.length; i++)
        {

        //System.out.println(names[i]);
        //System.out.println(passcodes[i]);

         if (passcodes[i]==passcode){
         System.out.println("Go to next page");
         System.out.println(names[i]);

}

Joe McG
  • 1
  • 1

1 Answers1

0

The == operator compares the object references, not the value of the Strings.

To compare the values of Strings, use the String.equals method:

if (passcodes[i].equals(passcode)) {...}
gio
  • 4,950
  • 3
  • 32
  • 46