title: How to count repeated numbers and write how many times
body: <p>In an array i want to count all duplicates and to write how many times they are repeated, how should i do it using only loops</p>
  
  <p>array example :
   int[] array = {12, 23, -22, 0, 43, 545, -4, -55, 43, 12, 0, -999, -87};</p>
  
  <p>This is my code </p>
  
  <pre><code>public static void main(String[] args) {
          int[] array = {12, 23, -22, 0, 43, 545, -4, -55, 43, 12, 0, -999, -87};
          int cntPoz = 0, cntNeg = 0;
  
          //for petlja broji pozitivne i negativne clanove array-a
          for (int a = 0; a &lt; array.length; a++) {
              if (array[a] &gt; 0) {
                  cntPoz++;
              } else if (array[a] &lt; 0) {
                  cntNeg++;
              }
          }
  
          // kreiranje novih nizova 
          int[] pArr = new int[cntPoz];
          int[] nArr = new int[cntNeg];
          //for petlja iz array-a premjesta sve pozitivne brojeve
          cntPoz = 0;
          for (int i = 0; i &lt; array.length; i++) {
              if (array[i] &gt; 0) {
                  pArr[cntPoz++] = array[i];
              }
          }
  
          //for petlja iz array-a premjesta sve negativne brojeve
          cntNeg = 0;
          for (int i = 0; i &lt; array.length; i++) {
              if (array[i] &lt; 0) {
                  nArr[cntNeg++] = array[i];
              }
          }
  
          //sortiranje i ispis nizova
          Arrays.sort(pArr);
          Arrays.sort(nArr);
          System.out.println("Originalni niz je : \n" + java.util.Arrays.toString(array) + "\n");
          System.out.println("Niz pozitivnih brojeva : \n" + java.util.Arrays.toString(pArr) + "\n");
          System.out.println("Niz negativnih brojeva : \n" + java.util.Arrays.toString(nArr));
          System.out.println();
          System.out.println();
  
  
          // for petlja prebrojava sve duplikate i ispisuje ih
          int dupCnt = 0;
          for (int i = 0; i &lt; array.length; i++) {
              for (int j = i+1; j &lt; array.length; j++) {
  
                  if ((array[j]) == array[i]) {
                      dupCnt++;
                      System.out.println("Duplicates  " + array[j]);
                  }
              }
          }
          System.out.println("Number of duplicates  : " + dupCnt);
  </code></pre>