title: Java program gives incorrect Taylor series term for function e^x
body: <pre><code>//java program that asks the user  to input a number that e^x=1+x+x^2/2! +x^3/3!... e is a mathematical constant equal to 2.718...
  
  import java.util.Scanner;
  public class taylor_2 {
    public static void main(String args[]) {
      Scanner input=new Scanner(System.in);
      double x; //input for x
      double factorial=1; //initializes factorial
      int counter=1; //initializes counter
      double result=1; //initializes result
  
      System.out.println(&quot;Enter non negative number&quot;); //asks user to enter x
      x=input.nextInt();
  
   //output in while loop will continue to be generated if user doesn't entered a negative number
  
      while(x&lt;1){
        System.out.println(&quot;I said entered a positive number&quot;);
        x=input.nextInt();
      }
      while(x&gt;counter){
        factorial=factorial*counter;//factorial formula
        result=result+(Math.pow(x,counter))/factorial; //equation for e^x=1+x+x^2/2! +x^3/3!
        counter++;
      }
      System.out.println(&quot;Taylor series is &quot; +result);//output for taylor equation e^x
    }
  }
  </code></pre>
  <p>Here is the output of my code:</p>
  <blockquote>
  <p>Enter non negative number</p>
  <p>2</p>
  <p>Taylor series is 4.0</p>
  </blockquote>
  <p>When I entered 2 , it should have outputted 7.3890560983 instead of 4.0 since e=2.718... and e^2=7.3890560983. What am I doing wrong?</p>