why am i getting NZEC runtime error error in java?

the program is ATM from easy practice section

    import java.io.*;
    class program
    {
    public static void main(String args[])throws IOException
    {
    InputStreamReader reader=new InputStreamReader(System.in);
    BufferedReader input=new BufferedReader(reader);
    int t;
    double i,c;
    t=Integer.parseInt(input.readLine());//to enter transaction amount
    i=Double.parseDouble(input.readLine());//to input initial balance
    int k=t%5;
    if(k==0&&t<=(i-0.50))
    {
    c=(i-t)-0.50;
    }
    else
    {
    c=i;
    }
    System.out.println(c);
    }
    }

Both the inputs are given in same line but you are reading two lines(one for integer and other for double). Instead read only one line and use stringTokenizer.

Thank you :slight_smile:

1 Like

As python or Java programming language supports exception handling, we can use exception handling using try-catch blocks to catch this error.

Some other ways to resolve the NZEC Error are:
Ensure that an illegal arithmetic operation like dividing by zero is not performed.
Using try-except blocks can help resolve NZEC errors most of the time.
Test your code and always check for corner cases.

Regards,
Rachel Gomez