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 a[]=new int[n+1];
  16. for(int i=1;i<=n;i++)
  17. a[i]=sc.nextInt();
  18.  
  19. // key=a[i], value=freq of a[i]
  20. Map<Integer,Integer> m=new HashMap<>();
  21. for(int i=1;i<=n;i++)
  22. m.put(a[i],m.getOrDefault(a[i],0)+1);
  23.  
  24. int q=sc.nextInt();
  25. while(q-->0)
  26. {
  27. int val=sc.nextInt();
  28. System.out.println("freq of "+val+" is : "+m.get(val));
  29. }
  30.  
  31. }
  32. }
Success #stdin #stdout 0.19s 60944KB
stdin
4
1
1
2
3

3
1
99
5
stdout
freq of 1 is : 2
freq of 99 is : null
freq of 5 is : null