Calculate Simple Interest in Java
Here you will get the example code to Calculate Simple Interest in Java programming.
Simple Interest Formula is :
SI = (P * R * T) / 100,
where SI is the interest, P is the principal amount, R is the interest rate, and T is the time in years.
Example code to Calculate Simple Interest in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //Calculate Simple Interest in Java import java.util.Scanner; public class SimpleInterest{ public static void main(String[] args) { double p,r,t,si; Scanner scanner = new Scanner(System.in); System.out.print("Enter the principal amount: "); p = scanner.nextDouble(); System.out.print("Enter the rate of interest (as percentage): "); r = scanner.nextDouble(); System.out.print("Enter the time (in years): "); t = scanner.nextDouble(); si = (p * r * t) / 100; System.out.println("Simple Interest: " + si); scanner.close(); } } |
Output
C:\CodeRevise\java>javac SimpleInterest.java
C:\CodeRevise\java>java SimpleInterest
Enter the principal amount: 5000
Enter the rate of interest (as percentage): 5
Enter the time (in years): 3
Simple Interest: 750.0
Check out our other Java Programming Examples