Monday 6 June 2016

Chapter 2 Exercise 20, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

*2.20 (Financial application: calculate interest) If you know the balance and the annual percentage interest rate, you can compute the interest on the next monthly payment 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. Here is a sample run:


import java.util.Scanner;
 
public class ProgrammingEx2_20 {
 
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
 
  System.out.print("Enter balance and interest rate (e.g., 3 for 3%):");
  double balance = input.nextDouble();
  double annualInterestRate = input.nextDouble();
  double interest = balance * (annualInterestRate/1200);
  System.out.print("The interest is " + interest);
 
 }
 
}

No comments :

Post a Comment