Guest User

Untitled

a guest
Jan 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Christian
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner input = new Scanner(System.in);
  8.        
  9.         System.out.print("Enter a number x to compute e^x: ");
  10.         int x = input.nextInt();
  11.         System.out.print("Enter a Number of Terms: ");
  12.         double n = input.nextDouble();
  13.        
  14.         double sum = 0;
  15.        
  16.         for(int i = 0; i < n; ++i)
  17.         {
  18.             sum += (Math.pow(x, i))/factorial(i);
  19.         }
  20.        
  21.         System.out.print(sum);
  22.     }
  23.    
  24.     public static double factorial(double n)
  25.   {
  26.       int ret = 1;
  27.       for (double i = 1.0; i <= n; ++i) ret *= i;
  28.       return ret;
  29.   }
  30. }
Add Comment
Please, Sign In to add comment