Scanner sc= new Scanner(System.in);
double x=sc.nextDouble();
double y=sc.nextDouble();
if(x<=y && x%5==0)
{
y-=x+0.50;
System.out.println(y);
}
else
System.out.println(y);
}
The initial balance must be more than the money requested plus 0.5 (the charge);
So, Your condition should be
if(x<y-0.5&&x%5==0)
Hope This may help!
this code may be not work because there would be two zeros after decimal so we should create an object of DecimalFormat .
int wd = sc.nextInt();
double bal = sc.nextDouble();
DecimalFormat df = new DecimalFormat("#.00");
if (wd < bal && wd % 5 == 0) {
System.out.println(df.format((bal - wd) - 0.5));
} else
System.out.println(df.format(bal));