I have left out something here or done something wrong??
Background:
We are supposed to implement a class ExpApproximator. It uses the power series and keep adding values until a summand (term) is less than a certain threshold. At each step, you need to compute the new term and add it to the total. Update these terms as follows: term = term * x / n;


public class ExpApproximator
{
public static double exp(int x)
{
final double epsilon = 0.01;
double term = 1;
double sum = 1;
double n = 1;
while(term > epsilon)
{
term *= x/n++;
sum += term;
}
return sum;
}

public static void main(String[] args)
{
System.out.println("e^x: " + exp(Integer.parseInt(args[0])));
System.out.println("e^x: " + Math.pow(Math.E,Integer.parseInt(args[0])));
}
}

what do you think it should do, and what does it do?

I see at least one error in your code, stemming from the way Java does division and multiplication and what you probably think it does.
You are missing a required cast somewhere, that's all I'll say for now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.