DEV Community

Kesavarthini
Kesavarthini

Posted on

đź’ł ATM Withdrawal Program Using If-Else in Java

📌 Introduction

ATM machines are a part of our daily life. One of the basic operations performed in an ATM is checking the balance condition before withdrawal.
In this blog, we will learn how to write a simple Java program using the if-else statement to simulate an ATM withdrawal condition by taking user input.

đź§  Problem Statement
• The minimum required balance is 5000
• If the user’s balance is less than 5000, display
👉 “Withdrawal successfully”
• If the user’s balance is greater than 5000, display
👉 “Withdrawal Failed”

đź’» Java Program

import java.util.Scanner;

class ATMWithdrawal {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter your balance: ");
        int balance = sc.nextInt();

        if (balance < 5000) {
            System.out.println("Withdrawal successfully");
        } else {
            System.out.println("Withdrawal Failed");
        }

        sc.close();
    }
}
Enter fullscreen mode Exit fullscreen mode

▶️ How the Program Works
1. The program asks the user to enter their balance.
2. The entered value is stored in the variable balance.
3. The if-else condition checks:
• If balance < 5000, the withdrawal is successful.
• Otherwise, the withdrawal fails.
4. The result is displayed on the console.

📤 Sample Input & Output

Input

Enter your balance: 3000
Enter fullscreen mode Exit fullscreen mode

Output

Withdrawal successfully
Enter fullscreen mode Exit fullscreen mode

Input

Enter your balance: 7000
Enter fullscreen mode Exit fullscreen mode

Output

Withdrawal failed
Enter fullscreen mode Exit fullscreen mode

Top comments (0)