title: How can I avoid repetition of the same number?
body: <p>This is what I want :<br>
  Let the user enter as many numbers as they want until a non number is entered (you may
  assume there will be less than 100 numbers). Find the most frequently entered number. (If
  there are more than one, print all of them.)<br>
  Example output:<br>
  Input: 5<br>
  Input: 4<br>
  Input: 9<br>
  Input: 9<br>
  Input: 4<br>
  Input: 1<br>
  Input: a<br>
  Most common: 4, 9<br>
  I have got to the point in my code where I have managed to find out which are the most common numbers. However, I don't want to print out the same number over and over again; example from above: Most common: 4, 9, 9, 4<br>
  What needs to be done?</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      String[] input = new String[100];
      System.out.print("Input: ");
      input[0] = in.readLine();
      int size = 0;
      for (int i = 1; i &lt; 100 &amp;&amp; isNumeric(input[i-1]); i++) {
              System.out.print("Input: ");
              input[i] = in.readLine();
              size = size + 1;
      }
      /*for (int i = 0; i &lt; size; i++) { //testing
          System.out.println(input[i]);
      }*/
      int numOccur;
      int[] occur = new int[size];
      for(int i = 0; i &lt; size; i++) {
          numOccur = 0;
          for (int j = 0; j &lt; size; j++) {
              if(input[i].equals(input[j])) {
                  numOccur = numOccur + 1;
              }
          }
          occur[i] = numOccur;
          //System.out.println(numOccur); //testing
      }
      int maxOccur = 0;
      for(int i = 0; i &lt; size; i++) {
          if(occur[i] &gt; maxOccur) {
              maxOccur = occur[i];
          }
      }
      //System.out.println(maxOccur); //testing
      for (int i = 0; i &lt; size &amp;&amp; !numFound; i++) {
          if(occur[i] == maxOccur) {
             System.out.println(input[i]);
          }
      }
  
  }
  
  //checks if s is an in, true if it is an int
  public static boolean isNumeric (String s) {
      try {
          Integer.parseInt(s);
          return true; //parse was successful
      } catch (NumberFormatException nfe) {
          return false;
      }
  }
  </code></pre>
  
  <p>Found the solution!</p>
  
  <pre><code>String[] mostCommon = new String[size];
      int numMostCommon = 0;
      boolean numFound = false;
      for (int i = 0; i &lt; size; i++) {
          int isDifferent = 0;
          if (occur[i] == maxOccur) {
              for (int j = 0; j &lt; size; j++) {
                  if (!(input[i].equals(mostCommon[j]))) {
                      isDifferent = isDifferent + 1;
                  }
              }
              if (isDifferent == size) {
                  mostCommon[numMostCommon] = input[i];
                  numMostCommon = numMostCommon + 1;
              }
          }
      }
      for (int i = 0; i &lt; numMostCommon - 1; i++) {
          System.out.print("Most common: " + mostCommon[i] + ", ");
      }
      System.out.println(mostCommon[numMostCommon - 1]);
  </code></pre>