Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:9)
The code:
import java.uitl.*;
public class Main {
public static void main (String args[]) {
int i;
int n;
Scanner s = new Scanner(System.in);
n = s.nextInt();
int a[] = new int[n];
for( i = 0; i<n; i++)
{
a[i] = s.nextInt();
}
int left=0,right=n-1;
int area=0;
while(left<right)
{
area=Math.max(area,(Math.min(a[left],a[right])*(right-left)));
if(a[left]<a[right]){
left=left+1;
}
else{
right=right+1;
}
}
System.out.println(area);
}
}