N. Achyut java,Java Introductions Write a program to input principle, time and rate, then calculate simple interest using static methods.

Write a program to input principle, time and rate, then calculate simple interest using static methods.

calculate simple interest using static methods.

Write a program to input principle, time and rate, then calculate simple interest using static methods using java.

Static Methods:

Static methods in Java that can be called without creating an object of class. They are referenced by the class name itself or reference to the Object of that class.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assignments;
import java.util.*;

/**
 *
 * @author achyut1324
 */
public class Qs4SimpleInterest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter principle time and rate respectively ");
        double p = in.nextDouble();
        double t = in.nextDouble();
        double r = in.nextDouble();
        System.out.println("Simple interest = "+ simpleInterest(p,t,r));
    }
    public static double simpleInterest(double p, double r, double t){
        return (p*t*r)/100;
    }
}

Output of the program :

run:
Enter principle time and rate respectively
2000
2
5
Simple interest = 200.0
BUILD SUCCESSFUL (total time: 9 seconds)

Related Post