正如所描述的標題,我想創建一個函數,告訴我兩個數字我給的是友好的,但由於某種原因,我得到了錯誤的答案,我希望有人會看到這個問題。友好的數字函數給出了錯誤的結果
public class Amicable{
public static void main(String[] args){
int n, m;
int ndivisorsSum = 0;
int mdivisorsSum = 0;
n = Integer.parseInt(args[0]);
m = Integer.parseInt(args[1]);
for(int i = 1; i < n; i++){
if (n % i == 0){
ndivisorsSum = ndivisorsSum + i;
}
}
for(int i = 1; i < m; i++){
if (m % i == 0){
mdivisorsSum = mdivisorsSum + i;
}
}
if (ndivisorsSum == mdivisorsSum) {
System.out.println(n + " and " + m + " are amicable numbers");
}else{
System.out.println(n + " and " + m + " are not amicable numbers");
}
}
}