Jan 15, 2022

Java Program To Calculate Simple & Compound Interest - Java Program With Example

Write a java program which accept principle, rate and time from user and print the simple and compound interest. 

The formula to calculate simple interest and compound intrest. Java programming solved programs. This program will calculate simple compound interest in Java programming .

Program Code

       

package com.androidpro.in;

import
java.io.BufferedReader;
import
java.io.InputStreamReader;
import
java.util.Scanner;

public class
Main {

   
public static void main(String[] args)
    {
       
double p, n, r, si, ci;

       
Scanner s = new Scanner(System.in);

       
System.out.print("Enter the amount : ");
       
p = s.nextDouble();

       
System.out.print("Enter the No.of years : ");
       
n = s.nextDouble();

       
System.out.print("Enter the Rate of interest : ");
       
r = s.nextDouble();

       
si = (p * n * r) / 100;
       
ci = p * Math.pow(1.0 + r / 100.0, n) - p;

       
System.out.println("\nAmount : " + p);
       
System.out.println("No. of years : " + n);
       
System.out.println("Rate of interest : " + r);
        
System.out.println("Simple Interest : " + si);
       
System.out.println("Compound Interest : " + ci);
   
}

}

       

   

Output

Enter the amount : 8000

Enter the No.of years : 5

Enter the Rate of interest : 6

 

Amount : 8000.0

No. of years : 5.0

Rate of interest : 6.0

Simple Interest : 2400.0

Compound Interest : 2705.8046208000014

 

Process finished with exit code 0

Whatsapp Button works on Mobile Device only