java program to calculate simple interest using function

write a program in java to take input from the user as principle, rate and time and calculate the simple interest.java program to calculate simple interest | java program to calculate simple interest using function.

step to find:-

  1. initialize a variable p and store the principal amount.
  2. r to store the rate the rate of interest.
  3. initialize a variable t and store the duration of time.
  4. use formula SI= (p*r*t)/100
  5. print the output.

Formula To calculate simple interest

Simple Interest = (p * n * r) / 100

where,

            p = Principal,

             n = Years

             r = Rate of Interest

example:-

              Principal Amount = ₹ 5000

              Period = 3 years

              Rate of Interest = 2%

              Simple Interest = ₹ 300

java program to find simple interest

package SimpleInterest;
// java program to find simple interest
import java.util.*; 
public class SimpleInterest{
 
    public static void main(String []args)
    {
        double p,r,t,SI;
        //user input.
        Scanner X = new Scanner(System.in);
        System.out.print("Enter Principle amount : ");
        p = X.nextFloat();
         
        System.out.print("Enter Rate of Interest: ");
        r =  X.nextFloat();
         
        System.out.print("Enter Time: ");
        t =  X.nextFloat();
         
        //Formula to find simple interest.
        SI = (p*r*t)/100;
         
        System.out.print("Total simple interest = "+SI+"\n");
                 
    }
}

sample output:-

example1:-

Enter Principal: 5000
Enter Rate o Interest: 2
Enter Time in years : 3
Simple Interest is :300.0

example2:-

Enter Principle : 15000
Enter Rate of Interest: 2
Enter Time in years : 2
Simple Interest is :400.0

output:-

java program to calculate simple interest using function
output:

java program to calculate simple interest using function

// java program to find simple interest
import java.util.*; 
public class SimpleInterest{
 
    public static void main(String []args)
    {
        double p,r,t,SI;
        //user input.
        Scanner X = new Scanner(System.in);
        System.out.print("Enter Principle amount : ");
        p = X.nextFloat();
         
        System.out.print("Enter Rate of Interest: ");
        r =  X.nextFloat();
         
        System.out.print("Enter Time: ");
        t =  X.nextFloat();
         
        //Formula to find simple interest.
       double interest = calculateInterest( p, t, r );
         
        System.out.print("Total simple interest = "+interest+"\n");
                 
    }
     public static double calculateInterest(double principal, double time, double rate) // LINE B
    {
        double result = (principal * time * rate )/ 100.0; // LINE C
        return result;
    }
}

 

C# Program To Calculate the Simple Interest

Python Program to Calculate Simple Interest using function

cpp program to calculate simple interest using function c++

C program to calculate simple interest using function

One Reply to “java program to calculate simple interest using function”

Leave a Reply

Your email address will not be published. Required fields are marked *