Example: Interest Payments

The interest due the second year on a $100,000 25 year loan is calculated. The loan is at 8%.
import com.imsl.finance.*;
import java.text.NumberFormat;

public class ipmtEx1 {
    public static void main(String args[]) {
        double rate = .08;
        int per = 2;
        int nper = 25;
        double pv = 100000.00;
        double fv = 0.0;
        int when = Finance.AT_END_OF_PERIOD;
        
        double ipmt = Finance.ipmt(rate, per, nper, pv, fv, when);
        System.out.println("The interest due the second year on the " +
        "$100,000 loan is " + NumberFormat.getCurrencyInstance().format(ipmt));
    }
}

Output

The interest due the second year on the $100,000 loan is ($7,890.57)
Link to Java source.