9. JAVA Program to find Simple Interest and Compound Interest.
How does this program work?
- In this programme you will learn about how to calculate Simple Interest and Compound Interest.
- This programme requires the user input to Enter the principle amount, time and rate of interest.
- This programme perform mathematical calculation and display the result using java.
Here is the code
//Simple and Compound interest
import java.util.Scanner;public class Interest
{
public static void main(String args[ ])
{
double p, rate, t, sim,com;
System.out.println("Enter amount:");
Scanner obj=new Scanner(System. in);
p=obj.nextDouble();
System. out. println("Enter the No.of years:");
t=obj.nextDouble(); System.out. println("Enter the Rate of interest");
rate=obj.nextDouble();
sim=(p * t * rate)/100;
// Formula for simple interest
com=p * Math.pow(1.0+rate/100.0,t) - p;// Formula for compound interest
System.out.println("Simple Interest="+sim );System.out. println("Compound Interest="+com);
}
}