MR_Whitehat

Compound Interest Calculation

Mar 27th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. package com.akshat.number_programs;
  2. //PROGRAM IS DEVELOPED BY AKSHAT DODHIYA
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class Compound_Interest {
  7.     public static void main(String[] args) {
  8.         Scanner sc=new Scanner(System.in);
  9.  
  10.         System.out.println("Enter the Principal amount");
  11.         double p = sc.nextDouble();
  12.  
  13.         System.out.println("Enter the annual rate of interest");
  14.         double r1 = sc.nextDouble();
  15.         double r = r1/100;
  16.  
  17.  
  18.         System.out.println("Enter the time period for which money is borrowed or invested(in Years only)");
  19.         double t = sc.nextDouble();
  20.  
  21.         System.out.println("Enter the  number of times the interest is compounded " +
  22.                 "(in numbers only) per unit 't' (For example yearly(12) , " +
  23.                 "half-yearly(6) , quarterly(4)");
  24.         double n = sc.nextDouble();
  25.  
  26.  
  27.         double amount = p * Math.pow((1 + (r/n)),(n*t));
  28.         double c_interest = amount - p;
  29.  
  30.  
  31.      DecimalFormat f = new DecimalFormat("##.00");
  32. //     Setting the pattern of two decimal place for the decimal number to be printed
  33.  
  34.  
  35.         System.out.println("Your Compound Interest is "+  f.format(c_interest));
  36.         System.out.println("Total Amount is "+f.format(amount));
  37. //        f.format() is used to set the declared format to the variable in parentheses
  38.     }
  39. }
Add Comment
Please, Sign In to add comment