在此代码中,当我在main方法中创建一个Object 然后调用该对象方法:( ff.twentyDivCount(i)运行在16010毫秒)时,它运行速度比使用此注释调用它快得多:( twentyDivCount(i)运行在59516毫秒).当然,当我在不创建对象的情况下运行它时,我将方法设为静态,因此可以在main中调用它.
public class ProblemFive {
// Counts the number of numbers that the entry is evenly divisible by, as max is 20
int twentyDivCount(int a) { // Change to static int.... when using it directly
int count = 0;
for (int i = 1; i<21; i++) {
if (a % i == 0) {
count++;
}
}
return count;
}
public static void main(String[] args) {
long startT = System.currentTimeMillis();;
int start = …Run Code Online (Sandbox Code Playgroud)