title: Needing help on printing mode in java
body: <p>I am given a task to make a method that takes a parameter of an ArrayList of Integer obj and print out the sum, average, and mode.</p>
  <p>I can't seem to figure out how to find the mode. It should print out the number if there is only one mode, and it should print out &quot;no single mode&quot; if there is more than one (or none) mode. My method only prints out &quot;no single mode&quot;. How can I fix my code to have the mode printed out?</p>
  <p>This is what I have for my code:</p>
  <pre><code>public static void printStatistics(ArrayList&lt;Integer&gt; arr){
  int sum = 0;
  for(int i : arr){
    sum += i;
  }
  System.out.println(&quot;Sum: &quot;+sum);
  System.out.println(&quot;Average: &quot;+(double)sum/arr.size());
  
  int temp = 0, counter = 0, max = 0;
  for(int j = 0; j &lt; arr.size() - 1; j++){
    for(int k = j+1; k &lt; arr.size(); k++){
      if(arr.get(j) == arr.get(k)){
        counter++;
        
        if(counter &gt; max){
          max = counter;
          temp = arr.get(j);
        }
        if(counter == max){
          temp = -1;
        }
      }
    }
  }
  if(temp &gt; 0){
    System.out.println(&quot;Mode: &quot;+temp);
  }
  else if(temp &lt; 0){
    System.out.println(&quot;Mode: no single mode&quot;);
  }
  </code></pre>
  <p>}</p>