getting run time error

hello friends I’m submitting ans of atm qs in JAVA language the code is

import java.util.Scanner;
public class Main
	public static void main(String[] args)
		float amm=0,w=0;
		Scanner i= new Scanner(;
		System.out.println("Inputn"); w=i.nextInt();
		if(amm>2000 || amm<0)
		if(w>2000 || w<0) System.exit(0); if(w>amm)
			System.out.println("Insufficient Funds");
		} if((w%5)!=0) 
			System.out.println("Invalid withdrawl ammount"); System.exit(0);
		amm=amm-w; System.out.println("Output:n"+(amm-0.5)); 

In my win7 based computer this code don’t show any runtime error but on submitting it shows runtime error please help me…

The First thing I did is -

Ran your code at ,the online compiler , your solution throws the following Exceptions-

Exception in thread "main" java.util.InputMismatchException
	at java.util.Scanner.throwFor(
	at java.util.Scanner.nextInt(
	at java.util.Scanner.nextInt(
	at Main.main(

So ,

obviously,you are getting a runtime error due to mismatch in input.

Just Read the problem statement again especially the Input format section :

*First Input:Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.

Second Input:Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja’s initial account balance.*

So ,the second input must be a floating point number.

But your code takes the second input as an Integer.


So,this is where the Mismatch occur and yes,that’s the reason ,you are getting a Runtime Error.

How to Recover?

Just Replace(Correct) the line amm=i.nextInt() with


So ,this will help you to Resolve the RunTime Error in your code. Check this Link

After resolving the runtime error [[ by just correcting a line that i mentioned above]] ,if you submit your solution ,you will get Wrong Answer :frowning:

Wrong answer as there are several mistakes in your code -

(1)There is no need to check whether the input data is valid or not :

        if(amm>2000 || amm<0)

Codechef is very strict .They will never provide a test data that doesnot satisfy the given constraint .
Refer the following FAQ

(2).You should not display

the input is [System.out.println(" Input\n............]

You should display the output in exactly the same way as mentioned in problem statement.
The printing of even additional whitespace results in wrong Answer.

(3).** Error(Logic/Strategical):**

Your logic is not correct.

(a)For successful transaction the sufficient and necessary condition is:

 (Amount pooja want to draw %5==0) && (withdraw amount  +.50(the bank service charge)) <= Balance amount.

But your code is not checking this codition.

Your solution allow pooja to make transaction even if (x%5) is not 0.

(b) If there is not enough money in the account to complete the transaction, just output the current bank balance.

You should not print :

"Insufficient Funds"

I will suggest you to read the problem statement once again and please must read all the FAQs ,several times :slight_smile:

1 Like

It is an item or gear issue that frustrates a framework from working adequately. Run-time errors Assignment Service UK done may make you lose information in the record you’re working upon.

Is it just me or the above answers seem like advertisements??

@admin, please have a look. :slight_smile:

All hubs are leaves that have an indegree (number of internal guided diagram edges to a given chart vertex in a coordinated diagram) of 0. aone-assignments So all hubs that are missing in the rundown of numbers given as information constitute the takes off. You have to print that leaves in rising request.

I am happy that we all help each other here. When I need help or advice, I only ask you guys!
By the way, if you are interested in interesting content or want to read interesting articles, visit
Thank you!