-2
我最近在競爭性編程中從C轉移到了Java。但是我提交的任何解決方案都會顯示NZEC運行時錯誤。一個這樣的問題是https://www.codechef.com/problems/FCTRL2 和我的解決辦法是爲什麼這段代碼不工作? FCTRL2
import java.util.Scanner;
import java.math.BigInteger;
class Solution{
public int t, i=0;
public BigInteger N;
public static void main(String args[]){
Solution sol = new Solution();
sol.scanT();
sol.testCase();
System.exit(0);
}
public void scanT(){
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
if(t>100 || t<1){
return;
}
}
public void testCase(){
Scanner sc = new Scanner(System.in);
for(i=0; i<t; i++){
N = sc.nextBigInteger();
if(N.compareTo(BigInteger.ONE)<0 || N.compareTo(BigInteger.valueOf(100))>0){
return;
}
BigInteger z = factorial();
System.out.println(z);
}
}
public BigInteger factorial(){
BigInteger Fact = N;
while(N.compareTo(BigInteger.valueOf(2))>0){
Fact = Fact.multiply(N.subtract(BigInteger.ONE));
N = N.subtract(BigInteger.ONE);
}
return Fact;
}
}
請幫我找到我的解決方案的錯誤,導致運行錯誤NZEC每次。我的解決方案在計算機上運行時顯示正確的輸出。
尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:[如何創建一個最小,完整和可驗證的示例。](http://stackoverflow.com/help/mcve) – user7
不確定問題是什麼,但爲什麼要創建多個掃描程序? – Ramanlfc
嘗試創建只有一個掃描儀 – user7