Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

getting "Wrong answer!"

$
0
0
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.


Viewing all articles
Browse latest Browse all 40121


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>