title: Comparing two integer arrays without sorting in java
body: <p>I am working on a piece of code which is used to create a multiple choice question exam. The purpose of the code I am working on is to enable a question to have multiple correct answers.</p>
  
  <p>The way a user inputs an answer is choosing an integer corresponding to the choice they would like to submit.</p>
  
  <p>The actual correct integer(s) is/are stored in an array called "correctedIndex" and the user stored responses are stored in an array called "response".</p>
  
  <p>The error I am having is checking to see whether the user's answers are correct, regardless of the order he or she submitted them in. My current idea was to created a nested for loop to cycle through both arrays and check for matches, and if the matches equal to the amount of correct answers, then the student would be correct. This does not work when I run it.</p>
  
  <p>Everything before that point works properly, I have made sure a user cannot enter invalid responses, duplicate responses, and automatically mark them incorrect if they submit more responses than there are correct responses.</p>
  
  <p>Here is the part of the code which does not work:</p>
  
  <pre><code>for(int i = 0; i &lt; correctIndex.length; i++){
              for(int j = 0; j &lt; response.length; j++){
                  if(correctIndex[i] == response[j]){
                      matches++;
                  }
              }
          }
          if(matches == correctIndex.length){
              System.out.println("Correct, answer was: ");
              for(int i = 0; i &lt; correctIndex.length; i++){
                  System.out.println((correctIndex[i] + 1) + ": " + choices[correctIndex[i]]);
              }
          }
          else{
              System.out.println("Your answer: ");
              for(int i = 0; i &lt; response.length; i++){
                  System.out.println(response[i] + ": " + choices[response[i]-1]);
              }
              System.out.println();
              System.out.println();
              System.out.println("Is incorrect, the correct answer is: ");
              for(int i = 0; i &lt; correctIndex.length; i++){
                  System.out.println((correctIndex[i] + 1) +": " + choices[correctIndex[i]]);
              }
          }
  </code></pre>
  
  <p>Here is an example of an output I get:</p>
  
  <pre><code>Please input the correct choice using its corresponding number
  
  Which of these are visibilities?
  
  1: Public
  2: Private
  3: Void
  4: Protected
  5: Int
  6: String
  7: Package-Protected
  
  Please enter how many answers you would like to select: 
  4
  Enter your number for answer 1
  1
  Enter your number for answer 2
  2
  Enter your number for answer 3
  4
  Enter your number for answer 4
  7
  </code></pre>
  
  <p>And here are the results after using the result method (The one in question):</p>
  
  <pre><code>Question: 
  Which of these are visibilities?
  
  Choices: 
  1: Public
  2: Private
  3: Void
  4: Protected
  5: Int
  6: String
  7: Package-Protected
  
  Your answer: 
  1: Public
  2: Private
  4: Protected
  7: Package-Protected
  
  
  Is incorrect, the correct answer is: 
  1: Public
  2: Private
  4: Protected
  7: Package-Protected
  </code></pre>