Java Programming

  1. Java Program: to calculate Compound Interest
    
      import java.util.Scanner;
    
      public class CompoundInterest {
      public static void main(String[] args) {
                                                                                                            
      // declare variables
      double principal = 0.0, rate = 0.0, time = 0.0;
      int number = 0;
      double totalAmount = 0.0, cinterest = 0.0;
                      
      // create object of Scanner class
      Scanner scan = new Scanner(System.in);
                      
      // read inputs
      System.out.print("Enter principal amount:: ");
      principal = scan.nextDouble();
      System.out.print("Enter the annual compound interest rate :: ");
      rate = scan.nextDouble();
      rate = rate/100; // convert rate
      System.out.print("Enter time (in years):: ");
      time = scan.nextDouble();
      System.out.print("Enter the number of times that "+
           +"interest is compounded per year:: ");
      number = scan.nextInt();
                      
      // calculate total amount
      totalAmount = principal * 
      Math.pow( 1+(rate/number), number*time);
                 
      // calculate compound interest
      cinterest = totalAmount - principal;
                      
      // display results
      System.out.println("Compound interest = "+ cinterest);
      System.out.println("Total amount = "+ totalAmount);
                      
      // close Scanner class object
      scan.close();
          }
    }
    
    
  2. Output:
    
    Enter principal amount:: 5000
    Enter the annual compound interest rate:: 5
    Enter time (in years):: 10
    Enter the number of times that interest is compounded per year:: 12
    Compound interest = 3235.0474884514006
    Total amount = 8235.0474884514
                  

Others Programming Language

article

programming C

Muktarul Hossain
article

C++

Muktarul Hossain
article

Python

Muktarul Hossain
article

Website Design

Muktarul Hossain