Java 为什么不是';这个代码不起作用吗?FCTRL2
我最近在竞争性编程中从C转向Java。但我提交的任何解决方案都会显示NZEC运行时错误。其中一个问题是 我的解决办法是Java 为什么不是';这个代码不起作用吗?FCTRL2,java,Java,我最近在竞争性编程中从C转向Java。但我提交的任何解决方案都会显示NZEC运行时错误。其中一个问题是 我的解决办法是 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
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;
}
}
import java.util.Scanner;
导入java.math.biginger;
类解决方案{
公共整数t,i=0;
公共大整数N;
公共静态void main(字符串参数[]){
溶液溶胶=新溶液();
sol.scanT();
sol.testCase();
系统出口(0);
}
公共空间不足{
扫描仪sc=新的扫描仪(System.in);
t=sc.nextInt();
如果(t>100 | | t由于同时使用System.in的多个扫描仪对象而产生NZEC错误。
只使用一个Scanner对象可以解决运行时错误NZEC的问题。寻求调试帮助的问题(“为什么此代码不工作?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题说明的问题对其他读者没有帮助。请参阅:不确定问题是什么,但是,为什么要创建多个扫描仪?尝试只创建一个扫描仪我认为这对我没有帮助你为什么不试试呢