NoSuchElementException error

I am getting a NoSuchElementException error in the following code while running it here but I am not getting any error when I run it on eclipse.

Any help would be appreciated .

problem :


import java.util.;

public class atm


public static void main(String[] args) 


	double w,c;

	Scanner input=new Scanner(;

	w=input.nextDouble();  //it is giving error at this line







	else if(w%5==0&&w>c)


	else if(w%5!=0)




just check if X is a multiple of 5, and Pooja’s account balance has enough cash to perform the withdrawal transaction(including bank charges).

If the above condition is true then c = c - w - .5, else c = c remains unchanged no need for the two elseif’s.

Make the above changes and you will get AC. :slight_smile:

Here is your updated code.

1 Like

thank you so much . but why was that error generated if you could share .

@itsmesiddhant if we don’t check that the file has next line before reading it, then it throws exception after reading last line since it is trying to read a line which doesn’t exist. This is one of the reasons for this error.

Thank you again . It is people like you that make people like me better.Thanks a lot !!

rjohari23, sir, the above mentioned link, in which there’s your version of code, even that is giving me NoSuchExceptionError in the line no.11 w=input.nextDouble();

NoSuchElementException: This is a Java specific error, when your code tries to read input more than available, such an Exception is thrown. Use of hasNext family of methods is advisable.