You are getting infinity simply because you are dividing the number by zero. The value of 1-(Math.pow(intrest / 400 + 1,(-1/3)))
is 0
Here is the debugged code:
public class Round {
public static void main(String args[]){
double intrest=8.5;
double quaters =21.0 / 3.0;
double first=intrest / 400.0 + 1 ;
double secound=(-1.0/3.0);
double amount=100.0;
System.out.println("intrest"+intrest);
System.out.println(secound);
System.out.println(quaters);
System.out.println(first);
System.out.println(Math.pow(intrest / 400 + 1, quaters) - 1);
System.out.println(1-(Math.pow(intrest / 400 + 1,(-1/3))));
double monthpayment = amount * ((Math.pow(intrest / 400 + 1, quaters) - 1) / (1-(Math.pow(intrest / 400 + 1,(-1/3)))));
System.out.println(monthpayment);
}
}
Here is the output for each line:
intrest8.5
-0.3333333333333333
7.0
1.02125
0.15857589055432686
**0.0**
Infinity
See you are dividing it by zero, hence you are getting infinity.
If you don't want infinity, you can just do following changes:
double monthpayment = amount * ((Math.pow(intrest / 400 + 1, quaters) - 1) / (1-(Math.pow(intrest / 400 + 1,((double)-1/3)))));
Now the value (1-(Math.pow(intrest / 400 + 1,((double)-1/3))))
would be 0.006984615789001336
instead of 0