001-004-004

Variable Value Update: Bank Balance Update

Easy

Problem Description

Repeated Variable Updates

Variable values can be updated multiple times. Use addition (+) and subtraction (-) to represent balance changes.

Points

  • Deposit: balance = balance + deposit;
  • Withdrawal: balance = balance - withdrawal;
.

Test Cases

※ Output examples follow programming industry standards

Input:
10000
5000
3000
Expected Output:
Initial Balance: 10000 yen
After Deposit: 15000 yen
After Withdrawal: 12000 yen
Input:
5000
10000
8000
Expected Output:
Initial Balance: 5000 yen
After Deposit: 15000 yen
After Withdrawal: 7000 yen
Input:
1000
0
0
Expected Output:
Initial Balance: 1000 yen
After Deposit: 1000 yen
After Withdrawal: 1000 yen
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// [入力準備] Scanner オブジェクトでキーボード入力を受け入れる
Scanner sc = new Scanner(System.in);
// 2. 初期残高
int balance = sc.nextInt();
System.out.println("Initial Balance: " + balance + " yen");
// 3. 入金
int deposit = sc.nextInt();
balance = balance + deposit;
// [出力処理] 結果を画面に表示
System.out.println("After Deposit: " + balance + " yen");
// 出金
int withdrawal = sc.nextInt();
balance = balance - withdrawal;
// [出力処理] 結果を画面に表示
System.out.println("After Withdrawal: " + balance + " yen");
}
}

0 B / 5 MB

You have 10 free executions remaining