This program takes user input for principal, rate of interest, and time period, and then it calculates and displays the simple interest based on those values.
In this program:
- We declare variables for principal (P), rate of interest (R), time period (N), and the calculated interest.
- We create a Scanner object named scanner to read input from the user.
- We prompt the user to enter the principal amount, rate of interest, and time period, respectively.
- We use scanner.nextFloat() to read float values for these inputs.
- We close the Scanner object to release resources.
- We calculate the simple interest using the formula (P * R * N) / 100 and store it in the interest variable.
- Finally, we display the calculated simple interest using System.out.println.
import java.util.Scanner; public class SimpleInterest { public static void main(String[] args) { float interest, p, r, n; Scanner scanner = new Scanner(System.in); System.out.print("Enter value of P: "); p = scanner.nextFloat(); System.out.print("Enter value of R: "); r = scanner.nextFloat(); System.out.print("Enter value of N: "); n = scanner.nextFloat(); scanner.close(); interest = (p * r * n) / 100f; System.out.println("Simple Interest: " + interest); } }
Follow Us