fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] arr = {2,3,4,1,1,2,4};
  13. findOdd(arr);
  14. }
  15.  
  16. public static void findOdd(int[] arr){
  17. HashMap hm = new HashMap();
  18. int value=0;
  19. for(int i=0;i<arr.length;i++){
  20. value=1;
  21. if(hm.containsKey(arr[i])){
  22. value = (Integer) hm.get(arr[i]);
  23. value++;
  24. }
  25. hm.put(arr[i], value);
  26. }
  27.  
  28. Iterator it = hm.entrySet().iterator();
  29. Map.Entry entry=null;
  30. while(it.hasNext()){
  31. entry = (Map.Entry)it.next();
  32. if((Integer)(entry.getValue())%2!=0){
  33. System.out.println((Integer)entry.getKey() +" has occurred odd no of time");
  34. }
  35. }
  36.  
  37. }
  38. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
3 has occurred odd no of time