forked from raman1200/community_issues
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculate Simple Interest Program in Java
34 lines (26 loc) · 1.23 KB
/
Calculate Simple Interest Program in 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
29
30
31
32
33
34
import java.util.Scanner;
public class SimpleInterestCalculator {
public static void main(String[] args) {
// Create a Scanner object to read user input
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the principal amount
System.out.print("Enter the principal amount: ");
double principal = scanner.nextDouble();
// Prompt the user to enter the rate of interest
System.out.print("Enter the rate of interest (in percentage): ");
double rateOfInterest = scanner.nextDouble();
// Prompt the user to enter the time period (in years)
System.out.print("Enter the time period (in years): ");
double time = scanner.nextDouble();
// Calculate the simple interest
double simpleInterest = calculateSimpleInterest(principal, rateOfInterest, time);
// Display the simple interest
System.out.println("Simple Interest: " + simpleInterest);
// Close the scanner
scanner.close();
}
// Function to calculate simple interest
public static double calculateSimpleInterest(double principal, double rateOfInterest, double time) {
return (principal * rateOfInterest * time) / 100;
}
}