getting "Wrong answer!"

import java.util.Scanner;

class ATM {
	
	public static void main(String args[]) {
		
		Scanner obj = new Scanner(System.in);
		System.out.println("Enter amount to be withdrawn");
		int wit = obj.nextInt();
		System.out.println("Enter initial balance");
		double bal = obj.nextDouble();
		if ((wit <= bal-0.5) && (wit % 5 == 0) && (wit > 0)) {
			
			System.out.println(String.format("%.2f", bal-wit-0.5));
		}
		else {
			
			System.out.println(String.format("%.2f", bal));
		}
	}
}

Why am I getting wrong answer here? What did I overlook?

This piece of code produces the desired results in my local computer just fine.

1 Like

The reason you are getting a wrong answer is this :-

  1. System.out.println(“Enter amount to be withdrawn”);
  2. System.out.println(“Enter initial balance”);
    You cant write this here. See the input output specifications mentioned in the problem page. It is required to print only what is mentioned in the i/o format, you cant print anything more or less. Look at the sample input/output of the problem for more details. If you have any more doubt then you can take a look at any accepted solution or ask again. Hope this helps. :slight_smile:

Ah, I see. Thanks a bunch!

2 Likes