Java Programming Exercise with Solution : Simple bank account practice

Exercise:
Get money and show balance until user put number <0

Example:
Put money : 400
Your Balance: 400
Put money : 100
Your Balance : 500
Put money : 200
Your Balance : 700
Put money : -1
Deposit completed.

Solution:

import java.util.Scanner;

public class CppToJava {

static int balance;

 static void bAccount(int a){
  balance+=a;
  System.out.println("Your balance: "+balance);
 }
 
 //This is main function
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int money;
  System.out.println("Simple Bank Account.");
  while(true){
   System.out.print("Money to save: ");
   Scanner myScanner = new Scanner(System.in);
   money = myScanner.nextInt();
   
   if(money<0){
    System.out.println("Deposit completed");
    break;
   }
   bAccount(money);
  }

 }

}

See also the same exercise with C++ programming.

Thank for visit my blog. Have a good day. :)