怎样编程求一个整数的所有公约数?
来源:百度知道 编辑:UC知道 时间:2024/04/28 16:26:47
最好用Java实现.
public class Gongyue {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = Integer.parseInt(args[0]);
for (int i=1;i<=n;i++){
if (n%i==0)
System.out.println(i);
}
}
}