import java.util.*;
public class Main
{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int sum = 0;
for(int I = 1; I <= x ; I ++){
if(x % I ==0){
sum += I ;
}
}
System.out.println ("The sum of the factors is " + sum);
}
}
程序應該輸入一個數字並打印出它的因子之和。但是,它是懸掛的。我將輸入代碼替換爲一個簡單的(int x = 10)代碼,我得到了所需的答案(18)。輸入Java代碼需要很長時間才能執行
你想要測試什麼輸入數字? – shmosel
這是你提到的情況,當你嘗試大量? – SmashCode
在掃描儀運行時間開始之前使用打印語句在您輸入數字之前,如果您輸入一個值時需要時間延遲,它會被添加到運行時間太清楚地說空閒時間也被計爲運行時間,一旦程序運行。希望您找到我的答案很有用。 – SmashCode