Simple Interest in Java
Calculate simple interest given principal, rate, and time.
BeginnerModule 1: Basic Java ProgramsExample 12 of 20
simple-interest.java
1import java.util.Scanner;23public class Main {4 public static void main(String[] args) {5 Scanner sc = new Scanner(System.in);67 System.out.print("Enter principal: ");8 double p = sc.nextDouble();9 System.out.print("Enter rate of interest: ");10 double r = sc.nextDouble();11 System.out.print("Enter time (in years): ");12 double t = sc.nextDouble();1314 double si = (p * r * t) / 100.0;15 System.out.println("Simple Interest = " + si);1617 sc.close();18 }19}
Output
Enter principal: 1000 Enter rate of interest: 5 Enter time (in years): 2 Simple Interest = 100.0
What's going on
Simple interest formula: SI = (P × R × T) / 100.