Run Time Error

Hello to everyone,

I’m trying to submit the solution of ATM problem but i’ve got some runtime error that i can’t solve someone could help me?

 import java.util.*;

 class Atm
 {
  public static void main (String[] args) 
  {
    double endAccountBalance;
    double taxes = 0.50;
    
	Scanner sc=new Scanner(System.in);

        int amount = sc.nextInt();
        double balance=sc.nextDouble();
    
        if(balance < 2000)
        {
           if(amount%5==0 && (amount+taxes)<balance)
           {
            endAccountBalance = balance-amount-taxes;
            System.out.println(endAccountBalance);
         }
       }
      }

        } 

Above is my code…

This is the error:

           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 Atm.main(Main.java:12)

Many thanks for your support!

BR

1 Like

Worked fine when I ran your code in Eclipse IDE , Only thing I changed was I added public as class modifier in ATM class.
i.e.
public class Atm{…}
Hope this helps :smiley:

I continue to have the same problem on the IDE of CodeChef…I can’t understand the error …

Did you provide required input in custom input?

1 Like

The IDE say that is not possible to compile the code…

I dont know mate i changed it back by removing public , your original code that is ran , on JAVA(HotSpot 8u112) on codechef compiler and it was executed normally , Inputs i gave were 800 1000.
Please try again it works.

I am also having the same issue.
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:6)

First give your input in input box, then click Run button