fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = scanner.nextInt();
  7.  
  8. int[] arr = new int[n];
  9. for (int i = 0; i < n; i++) {
  10. arr[i] = scanner.nextInt();
  11. }
  12. //take the no of queries
  13. int q = scanner.nextInt();
  14.  
  15. for (int i = 0; i < q; i++) {
  16. int query = scanner.nextInt();
  17.  
  18. int count = 0;
  19. for (int j = 0; j < n; j++) {
  20. if (arr[j] == query) {
  21. //increment the count once the no is available
  22. count++;
  23. }
  24. }
  25. //print the count
  26. System.out.println(count);
  27. }
  28. }
  29. }
  30.  
Success #stdin #stdout 0.11s 56528KB
stdin
5
1 2 3 3 4
2
1 3
stdout
1
2