用JAVA编写用户输入一个整数,求这个整数的因子和(所谓因子即可以被其整除的数,但本身不算,

2024-12-12 19:20:48
推荐回答(2个)
回答1:

public class Test1 {
public static void main(String[] args) {
int num = 1845;
int sum = 0;
System.out.println("因子:1");
sum += 1;
int sqrt = (int)Math.sqrt(num);
for(int i=2;i int j = num%i;
if(j==0){
System.out.println("因子:"+i);
sum += i;
int k = num/i;
System.out.println("因子:"+k);
sum += k;
}
}
System.out.println("因子和:"+sum);
}
}

回答2:

http://zhidao.baidu.com/question/544468708.html?sort=6&old=1&afterAnswer=1#answer-1374498178