此代码在我的笔记本电脑上运行完美,但我不知道在哪里出现运行时错误的问题?!!
谁能帮我找到问题?
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=979
这是我的代码:
import java.util.Scanner;
class Main
{
public static void main( String[] args ) /*throws IOException*/
{
Main myWork = new Main();
myWork.begin();
}
void begin()
{
Scanner input = new Scanner( System.in );
int inputArraySize; // size of array
int[] inputNumberSequence; // input sequence of numbers saved in array
while( true )
{
// jollyJumpers = new JollyJumpers( inputArraySize );
inputArraySize = input.nextInt();
inputNumberSequence = new int[ inputArraySize ];
for( int iii = 0; iii < inputArraySize; ++iii )
{
inputNumberSequence[iii] = input.nextInt();
}
if( jollyOrNotJolly( inputNumberSequence, inputArraySize ) )
System.out.println( "Jolly" );
else
System.out.println( "Not jolly" );
}
}
boolean jollyOrNotJolly( int[] inputNumberSequence, int inputArraySize )
{
int maxInteger = inputNumberSequence[0];
int minInteger = inputNumberSequence[0];
int summationOfInputNumberSequence = 0;
int temporaryElementFromList;
int summation_From_MinInteger_To_MaxInteger = 0;
for( int iii = 0; iii < inputArraySize; ++iii )
{
temporaryElementFromList = inputNumberSequence[ iii ];
if( temporaryElementFromList > maxInteger )
maxInteger = temporaryElementFromList;
else if( temporaryElementFromList < minInteger )
minInteger = temporaryElementFromList;
summationOfInputNumberSequence += temporaryElementFromList;
}
for( int jjj = minInteger; jjj <= maxInteger; ++jjj )
{
summation_From_MinInteger_To_MaxInteger += jjj;
}
return summationOfInputNumberSequence == summation_From_MinInteger_To_MaxInteger;
}
}
答案 0 :(得分:1)
可能已经有点晚了但是我建议在你的代码周围包装一个try-catch块,它可以捕获任何异常,只是打印出来。然后你会得到一个WA错误,你可以开始缩小try-catch,直到你再次遇到Runtime Exception。然后,您可以正确地确定抛出异常的位置。 至少就是我这样做的方式,面对的是我最初无法复制的例外情况。