我试图解决UVA问题Earn For Money ID:12614 在我的IDE上,我得到了所有案例的正确答案 但是当我提交uva在线评判时,我得到了一个运行时错误
有我的代码
import java.util.Scanner;
class Main{
/**
* UVAonlineJudge
*/
public static void main(String[] args) {
Main e = new Main();
Scanner scan = new Scanner(System.in);
final int T = scan.nextInt();
for(int i=0 ; i < T ; i++){
int N = scan.nextInt();
int[] array = new int[N];
String line = scan.nextLine();
int j = 0;
for(String num : line.split(" ")){
array[j] = Integer.parseInt(num);
j++;
}
int m= i+1;
System.out.println("Case "+ m + ": " + e.getMax(array));
}
scan.close();
}
int getMax(int[] array){
int first_max = array[0];
for(int i=1 ; i < array.length ; i++){
if(array[i] >first_max){
first_max = array[i];
}
}
return first_max;
}
}
答案 0 :(得分:1)
我想你会得到
Exception in thread "main" java.util.NoSuchElementException
NoSuchElementException 由枚举的 nextElement()方法抛出,表示枚举中没有其他元素。
点击此处查看有关No Such Element Exception
的更多信息因此直接使用scan.nextInt()
,首先使用hasNextInt()
检查元素是否存在
我还建议你使用 BufferedReader类来获取输入。