Thursday, June 19, 2014

Elementary Programming; Exercise No. 18

If you know the balance and the annual percentage interest rate, you can compute the interest on the next monthly pay ment using the following formula:
interest = balance * (annualInterestRate/1200)
Write a program that reads the balance and the annual percentage interest rate and displays the interest for the next month.

Solution:

public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
   double balance, annualInterestRate, interestRate;

   System.out.print("Enter balance and interest rate (e.g., 3 for 3%):");
   balance = s.nextDouble();
   annualInterestRate = s.nextDouble();

   interestRate = balance * (annualInterestRate / 1200);

   System.out.print("The interest is " + interestRate);
}

No comments:

Post a Comment

Author