How to Print Simple Interest in Java

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.

How to Accept Values of Two Numbers and Print their Addition

In this program:

  1. We declare variables for principal (P), rate of interest (R), time period (N), and the calculated interest.
  2. We create a Scanner object named scanner to read input from the user.
  3. We prompt the user to enter the principal amount, rate of interest, and time period, respectively.
  4. We use scanner.nextFloat() to read float values for these inputs.
  5. We close the Scanner object to release resources.
  6. We calculate the simple interest using the formula (P * R * N) / 100 and store it in the interest variable.
  7. 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);
    }
}
Join Now


Previous Year Questions Now to Boost Your Exam Performance

LOADS OF LOGIC