public class MmM{ public static void main(String[] args) { double[] data = {1, 1, 2, 2, 3 }; MmM.mode(data); } public static void mode(double [ ] numArray) { double f = 0; double hF=0; int length = numArray.length; for (int i = 0; i <length; ++i) { int count = 0; for (int j = 0; j <length; ++j) { if (numArray[j] == numArray[i]) { ++count; } } if (count > hF) { hF = count; f = numArray[i]; } } System.out.println("Mode = " + f); // I am trying to find mode. Out put of these codes is " 1 " // Required: Out put should be " 1 " and " 2 " both, because they both have highest and equal (i.e 2 times ) //numbers of repetitions which is the mode of the given items in the array // How do I achieve that both 1 and 2 instead of just 1 in the out put? } }