import static java.lang.Math.*;
import java.util.Vector;
public class Factors{
protected int m;
protected Vector myVector;
protected int primeFactors;
public Factors(int m) {
myVector=new Vector();
this.m=m;
primeFactors=0;
public Vector thefactors(){
for(int i=2;i<=Math.sqrt(m);i++) {
if (m%i==0) {
myVector.add(i);
}
primeFactors=myVector.add(i);
}
return this.get(primeFactors);
}
}
public static void main(String[] args) {
/*tests the methods implementation and
converts the command-line string arguments
to integers */
int num = Integer.parseInt(args[0]);
Factors roy = new Factors(num);
roy.thefactors();
}
}
答案 0 :(得分:4)
你在构造函数中有一个方法 - 不允许。
public Factors(int m) {
myVector=new Vector();
this.m=m;
primeFactors=0;
public Vector thefactors(){