Java Program that calculates monthly interest
Posted by Samath
Last Updated: January 08, 2021

An online bank wants you to create a program that shows prospective customers how their deposits will grow. Your program should read the initial balance and the
annual interest rate. Interest is compounded monthly. Print out the balances after the first three months. Here is a sample run:

Please enter Initial Balance: 1000

Please enter Annual intereset (%): 6.0

Balance after first month: 1005.00
Balance after second month: 1010.03
Balance after third month: 1015.08


import java.util.Scanner;

public class Main
	public static void main(String[] args) {
	    double account_bal;
	    double a_interest;
	    double m_interest;
	    double month1;
	    double month2;
	    double month3;
            Scanner in_value = new Scanner(;
            System.out.print("Please enter Initial Balance: ");
            account_bal = in_value.nextDouble();
            System.out.print("Please enter Annual intereset (%): ");
            a_interest = in_value.nextDouble();
            m_interest = a_interest / 12 / 100;
            month1 = account_bal + account_bal * m_interest;
            month2 = month1 + month1 * m_interest;
            month3 = month2 + month2 * m_interest;
            System.out.printf("Balance after first month: %.2f\n", month1);
            System.out.printf("Balance after second month: %.2f\n", month2);
            System.out.printf("Balance after third month: %.2f", month3);