# Mortgage calculator not printing monthly mortgage payment

**URL:** <https://forum.codewithmosh.com/t/mortgage-calculator-not-printing-monthly-mortgage-payment/6048>\
**Category:** Java\
**Created:** [July 11, 2021, 2:25am UTC](https://forum.codewithmosh.com/t/mortgage-calculator-not-printing-monthly-mortgage-payment/6048 "2021-07-11T02:25:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BForbes](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@BForbes](https://forum.codewithmosh.com/u/BForbes)\
**Post date:** [July 11, 2021, 2:25am UTC](https://forum.codewithmosh.com/t/mortgage-calculator-not-printing-monthly-mortgage-payment/6048/1 "2021-07-11T02:25:04Z")

</div>

So I tried my hand at the mortgage calculator and got stumped. I downloaded the source code as shown below and it does not print the monthly mortgage payment.

package com.codewithmosh;

import java.text.NumberFormat;  
import java.util.Scanner;

public class Main {

```
public static void main(String[] args) {
    final byte MONTHS_IN_YEAR = 12;
    final byte PERCENT = 100;

    Scanner scanner = new Scanner(System.in);

    System.out.println("Principal: ");
    int principal = scanner.nextInt();

    System.out.println("Annual Interest Rate: ");
    float annualInterest = scanner.nextFloat();
    float monthlyInterest = annualInterest / PERCENT / MONTHS_IN_YEAR;

    System.out.println("Period (Years): ");
    byte years = scanner.nextByte();
    int numberOfPayments = years * MONTHS_IN_YEAR;

    double mortgage = principal
                * (monthlyInterest * Math.pow(1 + monthlyInterest, numberOfPayments))
                / (Math.pow(1 + monthlyInterest, numberOfPayments) - 1);

    String mortgageFormatted = NumberFormat.getCurrencyInstance().format(mortgage);
    System.out.println("Mortgage: " + mortgageFormatted);
}

```

}

What am I missing? From what I can tell the last line should print the concatenated string. Is it because I’m using the most recent version of Java 16 and this program was written with version 12? I don’t understand why he would provide source code that doesn’t actually work. I compared it to the code in the video and everything looks the same. Any answers or insight would be greatly appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![Gintsm](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@Gintsm](https://forum.codewithmosh.com/u/Gintsm)\
**Post date:** [July 20, 2021, 5:24pm UTC](https://forum.codewithmosh.com/t/mortgage-calculator-not-printing-monthly-mortgage-payment/6048/2 "2021-07-20T17:24:19Z")

</div>

Hi, I copied Your code,  
and it worked. Tried on both IntelliJ IDE and Apache Netbeam (on this should be more accurate)  
using JDK 16
