ATM-NZEC Error

This is my solution for ATM problem and I’m getting Runtime Error : NZEC , how to solve it?Please help…

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
double amount_to_be_withdrawn,balance;
Scanner sc=new Scanner(System.in);
amount_to_be_withdrawn=sc.nextInt();
balance=sc.nextInt();
if(amount_to_be_withdrawn<balance)
{
double new_balance=balance-(amount_to_be_withdrawn+0.50);
System.out.println(new_balance);

	}
	else{
	    System.out.println(balance);
	}
}

}

1 Like

Please format your code as the forum software has messed it up or share you submission link.

2 Likes

how to format my code?please do help…I’m new into these

2 Likes

There’s a nice tutorial here :slight_smile:

1 Like

Thank you but as my code is in java anyways I got it …I have to use Try Catch block to get rid of NZEC error.

/* Final Code,if anyone need any help so just posted it */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try
{
double amount_to_be_withdrawn,balance;
Scanner sc=new Scanner(System.in);
amount_to_be_withdrawn=sc.nextFloat();
balance=sc.nextFloat();
if(amount_to_be_withdrawn%5==0 && amount_to_be_withdrawn+0.50<balance)
{
double new_balance=balance-(amount_to_be_withdrawn+0.50);
System.out.println(new_balance);

    	}
	    else{
	        System.out.println(balance);
	        }
    }
     catch(Exception e){
	    }
}

}

@noobcoder37 Its good that you got it, if you want to be careful in future about NZEC error code, there is nice article you can refer to.

1 Like

@noobcoder37 Still your code is messed up, well you can learn about using the forum as @ssjgz suggested in the above comments.
For now you can share your submission link.

1 Like

Article is really nice Thank you:grinning:

1 Like

@ssjgz yea that article is good too…thnx

1 Like

use try and catch method to solve the problem as u can see that main throws exception

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
float y = sc.nextFloat();
if(x%5==0 && y>=(x+0.5)){
System.out.printf(“%.2f”,y - (x+0.5));
}
else{
System.out.printf(“%.2f”,y);

    }
    }catch(Exception e){}
}

}