以下是计算最大产品子阵列的程序的代码。但是这段代码给了我以下异常: 运行时错误
线程“main”中的异常java.util.NoSuchElementException
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int noOfCases = s.nextInt();
// System.out.print("Enter length of array");
int n = s.nextInt();
int[] arr = new int[n];
int i=0;
// System.out.print("Enter array elements");
while(i<n){
arr[i] = s.nextInt(); //error here
i++;
}
largestProductSubarray(arr);
}
static void largestProductSubarray(int[] arr){
int n = arr.length;
int maxUntilNow = Integer.MIN_VALUE;
int productTillHere = arr[0];
for(int i=1; i<n; i++){
if(productTillHere ==0){
productTillHere = arr[i];
continue;
}
if(arr[i] < Math.abs(productTillHere * arr[i])){
productTillHere = productTillHere * arr[i];
}else{
productTillHere = arr[i];
}
maxUntilNow = Math.max(maxUntilNow, productTillHere);
}
System.out.print(maxUntilNow);
}
}