我用java做了一个分解程序。我在 Eclipse 中有一个带有 2 个包的项目。一个只有一个类,我遇到问题的那个,另一个包里面什么都没有。当我单击运行时,什么也没有发生,我不知道为什么。
这是java代码:
package com.frostbytedev.factor;
import java.util.ArrayList;
import java.util.Scanner;
public class factor {
static ArrayList<Integer> notFactors = new ArrayList<Integer>();
static ArrayList<Integer> factors = new ArrayList<Integer>();
static int i = 0;
/**
* @param args
*/
public static void main(String[] args){
// TODO Auto-generated method stub
Initialize();
}
private static void Initialize() {
// TODO Auto-generated method stub
System.out.println("Enter a number to factor below:");
Scanner in = new Scanner(System.in);
int number = in.nextInt();
FactorNumber(number);
PrintList(Factors);
}
private static void PrintList(ArrayList<Integer> factorsToPrint) {
// TODO Auto-generated method stub
for(i=0;i<factorsToPrint.size()-1;i++){
System.out.print(factorsToPrint.get(i)+", ");
}
System.out.print(factorsToPrint.size());
}
private static void FactorNumber(int number) {
// TODO Auto-generated method stub
for(i=2;i<number/2;i++){
if(number%i==0){
FactorNumber(i);
FactorNumber(number/i);
} else {
notFactors.add(i);
}
}
if(notFactors.size()==number){
factors.add(number);
}
};
}