java - 在线提交时Java代码错误"NZEC"

标签 java

当我运行以下代码(在系统编译器中)时,它运行良好,但是当我将其提交到站点时,所有测试用例都会抛出 nzec 运行时错误。不幸的是,该网站不共享测试用例,但可以使用问题创建它们。

谁能解释一下为什么会出现 nzec 错误吗?我使用了 java,因此代码抛出了需要捕获的异常:

import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import javax.swing.text.html.HTMLDocument.Iterator;

public class Readinput1 {

public static int readinput () throws IOException
{
    //InputStreamReader r=new InputStreamReader(System.in);  
    //BufferedReader br=new BufferedReader(r);  
      int n1=0;
      int name=0;
    System.out.println("Enter num");  
    //name=br.read(); 
//  if (name!=null){
    // n1=Integer.parseInt(name.trim());
     //     }
    Scanner in = new Scanner(System.in);
    name= in.nextInt();

    return name;

}


  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
 int num=0;

 ArrayList<Integer> al = new ArrayList<Integer>();
    while (num!=42)
            {
        num=readinput();

                al.add(num);


            }
    //Iterator itr=(Iterator) al.iterator();
    //while(((java.util.Iterator<Integer>) itr).hasNext()){ 
    al.remove(al.size()-1);
    //  String num1=itr.toString();
           //System.out.println(num1);  

     for (Integer integer : al) {
          System.out.println(integer);
        }
          }  


      }

最佳答案

有任何原因会抛出异常并产生所谓的NZCE

我不会给你解决方案,但会指出一些关键部分。

  • int n1=Integer.parseInt(name); - 考虑 name 不是有效的 Integer
  • al.remove(al.size()-1); - al 的大小是 0

关于java - 在线提交时Java代码错误"NZEC",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31099550/

相关文章:

java - 使用 FileReader read() 和 BufferedReader readLine() 对文件的行数和字符进行问题计数

java - 如何使用 Struts2 jQuery 从 external.js 获取 session 值

java - 如何用 ' ' 声明 int?为什么 '2' == 50?

java - XML 读出嵌套内容

java - 在 Eclipse 中引用文件而不对路径进行硬编码?

java - nzec 在 spoj 中出错,但在 eclipse 中工作正常

java - 测试类扩展依赖模块中的测试类

java - 如何在 Hadoop 中使用 CompressionCodec

java - 如何使用vertx解析查询参数?

java - Sqlexception 在 Mysql Workbench 上工作时对空结果集进行非法操作