 # Getting "wrong Answer" on Submitting the code

This is the question:
Pooja would like to withdraw X \$US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja’s account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 \$US. Calculate Pooja’s account balance after an attempted transaction.

### Input

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

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

### Output

Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.

This is my code:
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 Exception
{
try{

``````    int debit;
double bal=0.00;

if(debit>0 && bal>=0 && debit<=2000 && bal<=2000){

if(debit>bal)
System.out.println(String.format("%.2f", bal));
else if(debit%5!=0)
System.out.println(String.format("%.2f", bal));
else{
bal-=debit;
bal=bal-0.50;
System.out.println(String.format("%.2f", bal));
}

}
else System.exit(0);
}

catch(Exception e){
return;
}

}
``````

}

take a test case :
debit amount = 10
and current balance = 10
then your output = 10-10-0.5= -0.5
you have to check condition :

``````if(debit%5 == 0 && debit <= (balance - 0.5)){
balance = balance - debit-0.5;
print(balance)
}
``````
``````import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int debit = sc.nextInt();
double bal=sc.nextDouble();
if (debit%5 == 0 && debit <= (bal - 0.5)) {
bal = bal - debit- 0.5;
}

System.out.println(String.format("%.2f", bal));

}
}

``````