1// Java program to find simple interest
2import java.util.Scanner;
3public class SimpleInterestJavaProgram
4{
5 public static void main(String[] args)
6 {
7 float principal, rate, time;
8 Scanner sc = new Scanner(System.in);
9 System.out.print("Enter principal amount : ");
10 principal = sc.nextFloat();
11 System.out.print("Please enter rate annually : ");
12 rate = sc.nextFloat();
13 System.out.print("Please enter time(in years) : ");
14 time = sc.nextFloat();
15 float simpleInterest;
16 simpleInterest = (principal * time * rate) / 100;
17 System.out.println("The Simple Interest is : " + simpleInterest);
18 sc.close();
19 }
20}
1// Java program to calculate compound interest
2public class CompoundInterestDemo
3{
4 public void calculateCompound(int p, int t, double r, int n)
5 {
6 double number = p * Math.pow(1 + (r / n), n * t);
7 double interest = number - p;
8 System.out.println("Compound interest after " + t + " years: " + interest);
9 System.out.println("Money after " + t + " years: " + number);
10 }
11 public static void main(String[] args)
12 {
13 CompoundInterestDemo obj = new CompoundInterestDemo();
14 obj.calculateCompound(200000, 6, .06, 12);
15 }
16}