我用java製作了一個保理程序。我有一個項目在日食2包。一個人只有一個班,我遇到問題,另一個班裏什麼也沒有。 當我點擊運行,沒有任何反應,我不知道爲什麼。Java程序未運行
下面是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);
}
};
}
邊注:請在[Java的命名約定(http://java.about.com/od/javasyntax/a/nameconventions.htm),他們會更容易那些看你的代碼瞭解它 – BackSlash