Comparing the indexes of two arrays in Java
Hi all! I need help with a simple coding challenge. I am comparing two arrays but my code doesn't work the way it suppose to. Code should return 1 if the indexes are the same, otherwise -1, in a new array. Here is an example: Inputs: User-typed Array: ["cat", "blue", "skt", "umbrells", "paddy"] Correct Array: ["cat", "blue", "sky", "umbrella", "paddy"] Output: [1, 1, -1, -1, 1] My code returns all -1s. Can't figure out what is the issue. Thanks in advance! Here is my code: public class Challenge { public static int[] correctStream(String[] user, String[] correct) { int[] output = new int[user.length]; for (int i = 0; i < user.length; i++){ for(int j = 0; j < correct.length; j++){ if (user[i].equals(correct[j])){ output[i] = 1; } else{ output[i] = -1; } } }return output; } }