简体   繁体   English

为什么这段代码不起作用? FCTRL2

[英]Why isn't this code working? FCTRL2

I have recently shifted from C to Java in competitive programming.我最近在竞争性编程中从 C 转向了 Java。 But any solution which I submit shows me NZEC runtime error.但是我提交的任何解决方案都会显示 NZEC 运行时错误。 One such question is https://www.codechef.com/problems/FCTRL2 and my solution is一个这样的问题是https://www.codechef.com/problems/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;
    }
}

Kindly help me find the error in my solution which results in Runtime error NZEC everytime.请帮助我在我的解决方案中找到导致运行时错误 NZEC 每次的错误。 My solution shows correct output when run on my computer.我的解决方案在我的计算机上运行时显示正确的输出。

The NZEC error is generated due to multiple Scanner objects using System.in simultaneously. NZEC 错误是由于多个 Scanner 对象同时使用 System.in 而产生的。 Using only one Scanner object solves the problem of Runtime Error NZEC.仅使用一个 Scanner 对象解决了 Runtime Error NZEC 的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM