This article contains program in Java, to find and print simple interest based on the data entered by user at run-time. But before creating the program, let's remind the formula to calculate simple interest.
The formula to calculate simple interest is:
SI = (P*R*T)/100
where SI refers to the Simple Interest amount, P refers to the Principle amount, R refer to the Rate of Interest, and T refers to the Time Period in Years.
Compute Simple Interest in Java
The question is, write a Java program to compute simple interest based on principle, rate, and time period entered by user at run-time of the program. The program given below is answer to this question:
import java.util.Scanner; public class CodesCracker { public static void main(String[] args) { float p, r, t, si; Scanner scan = new Scanner(System.in); System.out.print("Enter the Principle Amount: "); p = scan.nextFloat(); System.out.print("Enter the Rate of Interest: "); r = scan.nextFloat(); System.out.print("Enter the Time Period (in Year): "); t = scan.nextFloat(); si = (p*r*t)/100; System.out.println("\nSimple Interest = " +si); } }
Here is its sample run with user input 1200 as principle amount, 8.5 as rate of interest, and 5 as number of years or time period (in years):
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.