Go to Top

Wednesday, 14 December 2011

To calculate the Compound Interest (C.I.)

Question 71 : Write a program in Java to find out Compound Interest (C. I.) on the basis of inputs accepted from the user.

Java Program :

import java.io.*;
class compound_interest
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     double p,r,t,a=0,n;
     System.out.println("\t\t*****Input Data*****\n");
     System.out.print("Enter the principal amount : Rs. ");
     p=Double.parseDouble(br.readLine());
     System.out.print("\nEnter the rate of interest (w/o % sign) : ");
     r=Double.parseDouble(br.readLine());
     System.out.print("\nEnter the time in yrs. : ");
     t=Double.parseDouble(br.readLine());
     System.out.print("\nHow many times a year is the interest calculated (Ex.: Half-yearly : 2 times) ? : ");
     n=Double.parseDouble(br.readLine());
     a=p*(Math.pow((1+(r/(n*100))),(t*n)));
     System.out.println("\n\t\t*****Results*****\n");
     System.out.println("Compound interest : Rs. "+(a-p));
     System.out.println("\nAmount : Rs. "+a);
    }
} 

2 comments:

ShareThis