-3
我想解决本网站上的问题:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=979。但我的代码的一部分引发运行时错误:Java 1.7运行时错误
class Main {
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main(String[] args){
Main jollyJumper = new Main();
jollyJumper.start();
}
public void start(){
String input;
while((input = ReadLn(3000)) != null){
System.out.println(answer(input));
}
}
public String answer(String line){
// The error comes from this function !!!
String[] items = line.split(" ");
int[] array;
try {
array = new int[items.length - 1];
}
catch(NegativeArraySizeException e){
return "Not jolly";
}
for(int i = 0; i < array.length; i++){
array[i] = Integer.parseInt(items[i +1]);
}
return "Jolly";
}
}
但判断系统不会告诉我哪里是错误,并在我的电脑上一切工作正常。有任何想法吗?
请告诉我们堆栈跟踪 – user
没有足够的代码来告诉你程序在哪里出错。它会很容易崩溃。请提供isJolly()。 – laune
@user:该站点的在线判断系统不提供堆栈跟踪,它实际上只提供字符串“运行时错误”。 –