NoElementException Found

while taking input for an array I am getting the Above Mentioned Exception my code goes like this:

Scanner sc=new Scanner(System.in);
int n=sc.nextInt();

int height[]=new int [n];

for(int i=0;i<n;i++){

height[i]=sc.nextInt();

}

I have imported java.util package but still scanner is not working

Can you send me your entire code in the ideone. It seems correct. I’ll check if there’s any other error.

https://ide.codingblocks.com/s/258268 i am getting 40 as a output but answer is 49

the question is getting max area for storing water in a container

@dheerajmishra992 initialize left 0 and right to height.length-1 (line 7)

https://ide.codingblocks.com/s/258268 i am getting no element exception while taking input from scanner that means my scanner is not taking input please help

@dheerajmishra992 no bro as i told you above you initialized left and right wrong which lead to out of bound array here corrected

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.