on Leave a Comment

Java Program to Calculate Simple and Compound Interest

This java program calculates simple and compound interest. First, user enters the amount, number of years and rate of interest, then calculates simple interest and compound interest. 

Java Program to Calculate Simple and Compound Interest

 import java.util .*;

 class SiCi
{
 public static void main(String[] args) {
 double p, rate, t, si, ci;
        System.out.print("Enter The Amount : ");
        Scanner read = new Scanner(System. in);
     p = read.nextDouble();

     System. out. print("Enter The No. of Years : ");
    t = read.nextDouble();

     System. out. print("Enter The Rate of Interest (ROI) : ");
     rate = read.nextDouble();

     /*Calculating Simple Interest and Compound Interest*/
     si = (p * t * rate)/100;
     ci = p*Math.pow(1.0+rate/100.0,t)-p;

     /*Displaying Simple Interest and Compound Interest*/
     System.out.println("Simple Interest = "+si);
     System.out. println("Compound Interest = "+ci);
 }
}

Output:

Enter The Amount : 1000
Enter The No. of Years : 2
Enter The Rate of Interest (ROI) : 15
Simple Interest = 300.0
Compound Interest = 322.4999999999998


0 comments:

Post a Comment