PDA

View Full Version : Help with Math.pow using variable



onedollartotown
01-21-2009, 07:00 AM
Hi Guys,

I need help on how to use inputs for the Math.pow class which is represented by the variable n(the number of years).

public class ComputeInterest {
public static void main(String[ ] args) {

double L = Double.parseDouble(args[0]);
double i = Double.parseDouble(args[1]);
double n = Double.parseDouble(args[2]);


double C = L * (1 + i/100)n; // <<the power of n should be placed as follows.



System.out.println(C);

}}

Regards,
John

Twey
01-21-2009, 07:15 AM
Math is a class. Math.pow is a method. Capital letters are conventionally reserved for classes.
public class ComputeInterest {
static double computeInterest(double loan,
double interest,
double years) {
return loan * Math.pow(1 + interest/100, years);
}

public static void main(String[] args) {
System.out.println(
computeInterest(Double.parseDouble(args[0]),
Double.parseDouble(args[1]),
Double.parseDouble(args[2])));
}
}

onedollartotown
01-21-2009, 08:24 AM
Hi Twey. Thanks for the help. Works like charm.