TL; DR--如何让java.util.NoSuchElementException返回null而不是错误并使程序崩溃。如何避免“java.util.NoSuchElementException”崩溃我的程序
我在写一个应该从文本文件中读取一系列整数的程序。在程序中,每次运行它时,整数的数量都会有所不同。我写了一段代码,它会读取整数,我想知道如何使java.util.NoSuchElementException不会使我的程序崩溃,而是返回null。
我已经writen其代码的情况下,你是好奇如下
public static void main(String[] args) throws IOException{
Scanner Input = new Scanner(new File("newestcode.txt"));
Integer[] digits = new Integer[100];
int h = 0;
while(true){
digits[h] = Input.nextInt();
h++;
System.out.println(digits[h]);
}
}
,程序我要写作是一种对坏加密引擎解密引擎的我写的一天
你听说过试穿吗? –
请按照字段的命名约定,使用camelCase。因为你的字段'Input'可能看起来像一个类,使用静态方法。 – StarCoder