2015-06-28 39 views
0

当我运行下面的代码(在系统编译器中)时,它运行良好,但是当我将它提交给站点时,所有测试用例都会抛出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); 
     } 
      } 


     } 
+0

请提供完整的错误消息。 – barthel

+0

运行时错误(NZEC) – krishna

+1

'NZEC'没有帮助。请描述“我已将其提交给网站”。你在http://www.codechef.com/或类似的? – barthel

回答

2

有任何理由抛出异常,并产生所谓的NZCE

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

  • int n1=Integer.parseInt(name); - 想想name不是有效Integer
  • al.remove(al.size()-1); - 什么是对的al大小为
+0

现在我已经修改代码来获取整数,但仍然错误仍然存​​在。 for al.remove(al,size() - 1);我们得到的输入数是!42,因此总是大于1。 – krishna