-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatingSimpleInterest.java
29 lines (21 loc) · 1.09 KB
/
CalculatingSimpleInterest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Importing the Scanner class to take user input
import java.util.Scanner;
public class CalculatingSimpleInterest {
public static void main(String[] args) {
// Creating a Scanner object to read input from the user
Scanner sc = new Scanner(System.in);
// Prompting the user to enter the principal amount
System.out.print("Enter Principal amount: ");
double principal = sc.nextDouble(); // Reading principal amount
// Prompting the user to enter the rate of interest (in percentage)
System.out.print("Enter Rate of Interest (in %): ");
double rate = sc.nextDouble(); // Reading interest rate
// Prompting the user to enter the time duration (in years)
System.out.print("Enter Time (in years): ");
double time = sc.nextDouble(); // Reading time period
// Calculating Simple Interest using the formula: (P × R × T) / 100
double simpleInterest = (principal * rate * time) / 100;
// Displaying the calculated Simple Interest
System.out.printf("Simple Interest: ", simpleInterest);
}
}