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. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int n=sc.nextInt();
  15. int arr[]=new int[n];
  16.  
  17. for(int i=0;i<n;i++)
  18. arr[i]=sc.nextInt();
  19.  
  20. Map<Integer,Integer> hash=new HashMap<>();
  21.  
  22. for(int ele:arr)
  23. hash.put(ele,hash.getOrDefault(ele,0)+1);
  24. int q=sc.nextInt();
  25. while(q-->0)
  26. {
  27. int query=sc.nextInt();
  28. System.out.println("the Freq of "+query+" is : "+hash.get(query));
  29. }
  30.  
  31.  
  32.  
  33.  
  34. }
  35. }
Success #stdin #stdout 0.2s 60872KB
stdin
5
1 2 2 3 3 
3
1
3
2
stdout
the Freq of 1 is : 1
the Freq of 3 is : 2
the Freq of 2 is : 2