Simple Interest

Calculate simple interest given principal, rate, and time.

BeginnerTopic: Module 1: Basic Java Programs
Back

Java Simple Interest Program

This program helps you to learn the fundamental structure and syntax of Java programming.

Try This Code
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter principal: ");
        double p = sc.nextDouble();
        System.out.print("Enter rate of interest: ");
        double r = sc.nextDouble();
        System.out.print("Enter time (in years): ");
        double t = sc.nextDouble();

        double si = (p * r * t) / 100.0;
        System.out.println("Simple Interest = " + si);

        sc.close();
    }
}
Output
Enter principal: 1000
Enter rate of interest: 5
Enter time (in years): 2
Simple Interest = 100.0

Understanding Simple Interest

Simple interest formula: SI = (P × R × T) / 100.

Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.

Table of Contents