title: How to compare user input in array?
body: <p>Hi guys sorry I'm a newbie to Java, this is one of the exercise in my class.
  I supposed to ask user input 5 numbers, then compare them if they are the same number that entered before. 
  These are my code so far, but I can't get it work.
  Thanks.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Source {
      private static int num = 0;
      private static int[] enterednum = new int[5];
  
      public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
  
          for(int count = 0; count &lt; enterednum.length; count++) {
              System.out.println("Enter a number.");
              num = input.nextInt();
  
              compare(enterednum);
          }
  
          System.out.println("These are the number you have entered: ");
          System.out.println(enterednum);
      }
  
      public static void compare(int[] enterednum) {
          for(int count = 0; count &lt; 6; count++)
              if(num == enterednum[count])
                  System.out.println("The number has been entered before.");
      }
  }
  </code></pre>