I am trying to write a program that will calculate monthly payments based on information entered by the user. however, when i used math.pow it returns infinity. i know my formula is right i have tested it with a calculator 100 times now, i just dont get why its returning infinity.
this is my code...
[code=java]
import java.util.Scann er;
public class problem2 {
public static void main(String[]args)
{
double interestRate;
double years;
double mortgage;
double monthlyPay;
double mIR;
double nOY;
Scanner scan = new Scanner(System. in);
System.out.prin tln("Enter the interst rate.");
interestRate=sc an.nextDouble() ;
System.out.prin tln("Enter the duration of the loan in years.");
years=scan.next Double();
System.out.prin tln("Enter the amount of the mortgage.");
mortgage=scan.n extDouble();
mIR=interestRat e/12;
nOY= 12*years;
monthlyPay = Math.pow((mIR*m ortgage)/ (1-(1/(1+mIR))),nOY);
System.out.prin tln(monthlyPay) ;
}
}[/code]
this is my code...
[code=java]
import java.util.Scann er;
public class problem2 {
public static void main(String[]args)
{
double interestRate;
double years;
double mortgage;
double monthlyPay;
double mIR;
double nOY;
Scanner scan = new Scanner(System. in);
System.out.prin tln("Enter the interst rate.");
interestRate=sc an.nextDouble() ;
System.out.prin tln("Enter the duration of the loan in years.");
years=scan.next Double();
System.out.prin tln("Enter the amount of the mortgage.");
mortgage=scan.n extDouble();
mIR=interestRat e/12;
nOY= 12*years;
monthlyPay = Math.pow((mIR*m ortgage)/ (1-(1/(1+mIR))),nOY);
System.out.prin tln(monthlyPay) ;
}
}[/code]
Comment