0
我編寫了用於查找兩個數組中發生的常見元素計數的代碼,但是我的輸出僅給出了我聲明的數組大小。任何人都可以請指出我的代碼中的錯誤?使用HashMap查找兩個相等大小的數組中的相似元素的計數
import java.io.*;
import java.util.*;
public class arreq1 {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
//int t = in.nextInt();
int n = in.nextInt();
int p[] =new int[n];
int c[] =new int[n];
int count=0;
for(int i=0;i<n;i++)
p[i] = in.nextInt();
for(int k=0;k<n;k++){
c[k] = in.nextInt();
}
for(int j=0;j<p.length;j++){
hm.put(p[j],j);
if(hm.containsKey(c[j]));
count++;
}
System.out.println(count);
}
}
發現分號錯誤,感覺自己很傻。非常感謝你:) –